JS Built-ins
← Proxy18 / 100
Proxyhasintermediate

Proxy has trap β€” always false

πŸ“– Usage Example
const p = new Proxy({}, {
  has: (target, key) => key.startsWith('a')
})
console.log('apple' in p)  // β†’ true
console.log('banana' in p) // β†’ false

The has trap intercepts the in operator, allowing you to control which property names are considered present on a proxy.

has trap β€” hide all properties

When the has trap always returns false, no key ever appears present β€” even if the target has it.

Challenge: Verify that 'x' in p is false when the has trap always returns false.

πŸ’‘ Hints (1)
  • β€’ The `has` trap can lie β€” returning `false` even if the target has the property.