What is the output of the following? “`js const target = { a: 1 }; const handler = { set(obj, prop, value) { obj[prop] = value * 2; return true; } }; const p = new Proxy(target, handler); p.b = 5; console.log(target.b); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js const target = { a: 1 }; const handler = { set(obj, prop, value) { obj[prop] = value * 2; return true; } }; const p = new Proxy(target, handler); p.b = 5; console.log(target.b); “`

Key points

  • The handler's `set` function modifies the value before setting it on the target object
  • Proxy intercepts property assignments and applies the handler's logic
  • The original target object is updated with the modified value

Ready to go further?

Related questions