What are proxies in JavaScript?

Proxies enable custom behavior for fundamental operations like getting, setting, and deleting properties on objects. They are created with a handler object that defines traps, or methods, for various operations, making them useful for tasks like validation, data binding, and observability.

const target = { name: "Alice" };
const handler = {
  get: (obj, prop) => (prop in obj ? obj[prop] : "Property not found"),
};
const proxy = new Proxy(target, handler);
console.log(proxy.name); // "Alice"
console.log(proxy.age);  // "Property not found"