Favorites

JavaScript Proxy Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Proxy
JavaScript Reflection · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

A Proxy wraps an object and lets you intercept operations on it, such as reading or setting properties, through handler functions called traps.

Description

A Proxy creates a stand-in for another object, the target, and lets you intercept fundamental operations on it. The handler object defines traps, such as get, set, has, deleteProperty and apply, which run instead of the default behavior. Any operation without a trap goes straight to the target.

Proxies are used for validation, logging, default values, change tracking in UI frameworks and creating objects with dynamic properties. Inside a trap, the matching Reflect method performs the default action. Proxies add overhead to every operation, so avoid them in performance-critical code.

Some operations can't be intercepted, such as strict equality comparisons, and traps must respect certain rules called invariants; for example, a get trap can't report a different value for a non-writable, non-configurable property. Proxy.revocable() creates a proxy that can later be switched off, after which any operation on it throws a TypeError, which is useful for granting temporary access to an object.

Creating

new Proxy(target, handler)

Example

const user = { name: 'Sam', age: 30 };

const guarded = new Proxy(user, {
  get(target, prop) {
    return prop in target ? target[prop] : `No property "${String(prop)}"`;
  },
  set(target, prop, value) {
    if (prop === 'age' && typeof value !== 'number') {
      throw new TypeError('age must be a number');
    }
    return Reflect.set(target, prop, value);
  },
});

console.log(guarded.name, guarded.email);
guarded.age = 31;
try { guarded.age = 'old'; } catch (e) { console.log(e.message); }

Browser Support

The following information will show you the current browser support for the Proxy object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee