What is the Proxy object in JavaScript?
Answer
The Proxy object (ES6) wraps another object and intercepts fundamental operations on it, allowing custom behavior for property access, assignment, function calls, and more. Create: new Proxy(target, handler). The handler defines traps: get(target, prop) — intercept property reads, set(target, prop, value) — intercept property writes, has(target, prop) — intercept in operator, deleteProperty, apply (function calls), construct (new operator). Example — validation: const validatedUser = new Proxy({}, { set(obj, prop, value) { if (prop === "age" && typeof value !== "number") throw TypeError("Age must be a number"); return Reflect.set(obj, prop, value); } }). Use cases: validation, logging, data binding, React-like reactivity (Vue 3 uses Proxy), virtual properties, API mocking. Proxy enables meta-programming — code that programs code. Always use Reflect methods for the default behavior in traps.