JS Built-ins
Proxygetbeginner

Proxy get trap β€” always return intercepted

πŸ“– Usage Example
const p = new Proxy({}, {
  get: (target, key) => 'got ' + String(key)
})
console.log(p.foo) // β†’ 'got foo'
console.log(p.bar) // β†’ 'got bar'

The get trap intercepts property reads on a proxy, letting you return custom values for any key instead of actual target values.

get trap β€” intercept all reads

A get trap that ignores the target always returns a fixed value for any property.

Challenge: Verify that p.anything === 'intercepted' when get always returns 'intercepted'.

πŸ’‘ Hints (1)
  • β€’ Returning a constant in the `get` trap intercepts all property reads.