Intercept Access with Proxy
Write a JavaScript function that creates a Proxy around a target object. The Proxy intercepts get operations to return the property value doubled, and intercepts set operations to log the action without actually storing the value. Return the Proxy-wrapped object.
The Proxy object in JavaScript enables custom behavior for fundamental operations on objects. A Proxy wraps a target object and intercepts operations via handler functions (traps). Common traps include get (property access), set (property assignment), has (in operator), deleteProperty, and apply (function call).
Proxies are a powerful metaprogramming feature unique to JavaScript. They enable use cases like validation, logging, profiling, access control, and reactivity (as used in Vue 3). Unlike getters/setters which work on individual properties, Proxies can intercept ALL operations on an object without modifying the original object.
Time complexity is O(1) per trapped operation. The get and set traps add minimal overhead compared to direct property access. Proxies are transparent — code using the proxied object generally cannot tell it's a Proxy.
Edge cases include intercepting non-existent properties (get returns undefined doubled = NaN, set still logs), prototype chain lookups, and ensuring the set trap returns true to indicate successful assignment (required by the Proxy specification).
Example Input & Output
7*2=14
0*2=0
Accessing x returns 5*2=10
Accessing y returns 10*2=20
3*2=6
Algorithm Flow

Solution Approach
Best Answers
function solution(target) {
return new Proxy(target, {
get: function(obj, prop) {
return obj[prop] * 2;
},
set: function(obj, prop, value) {
console.log('Setting ' + prop + ' to ' + value);
return true;
}
});
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
