JS Built-ins
← Proxy10 / 100
Proxygetintermediate

Proxy get trap β€” typeof key

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

Property keys are strings (or Symbols). A get trap returning typeof k will return 'string' for any string key.

Challenge: Verify that p.foo === 'string' when get returns typeof k.

πŸ’‘ Hints (1)
  • β€’ String property keys have `typeof key === 'string'`.