Proxies in JavaScript allow you to execute a function when reading/setting an object property.
const handler = {
get: function(target, prop) {
return `Accessing property: ${prop}`;
}
};
const obj = { name: "ChatGPT" };
const proxy = new Proxy(obj, handler);
console.log(proxy.name); // Output: "Accessing property: name"