JS Built-ins
← Proxy17 / 100
Proxyhasbeginner

Proxy has trap β€” passthrough for existing key

πŸ“– 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 β€” passthrough

Without a has trap, the in operator checks the target directly.

Challenge: Verify that 'a' in new Proxy({a: 1}, {}) is true.

πŸ’‘ Hints (1)
  • β€’ Without a `has` trap, `in` checks the real target.