What is the output of the following? “`js const target = {}; const handler = { get(t, key) { return key in t ? t[key] : `Property ${key} not found`; } }; const proxy = new Proxy(target, handler); target.name = ‘Alice’; console.log(proxy.name); console.log(proxy.age); “`
Key points
- The Proxy object allows custom behavior for fundamental operations.
- The handler's get method checks if a property exists in the target object.
- If a property is not found, the handler returns a custom message.
- The Proxy object intercepts operations on the target object.
Ready to go further?
