JS Built-ins
← Proxy19 / 100
Proxyhasintermediate

Proxy has trap β€” only x is present

πŸ“– 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 β€” selective key visibility

The has trap receives (target, key). You can conditionally return true only for specific keys.

Challenge: Verify that 'x' in p is true when has returns key === 'x'.

πŸ’‘ Hints (1)
  • β€’ Use `k === 'x'` to allow only the key `'x'` through the trap.