Learn JavaScript
❯ objects.proxies

Proxies & Reflect in JavaScript

$concept

Proxies intercept object operations through handler traps: get/set/has/deleteProperty plus function traps (apply/construct), with Reflect.* providing the default behaviors to wrap. Validation (reject bad sets), logging, defaults, and revokable membranes (Proxy.revocable) all build from a dozen traps.

Invariants constrain: non-configurable properties can't lie about existence or values, and private fields ignore proxies entirely. Proxies power frameworks (Vue reactivity, Immer drafts) far more than application code — understand them to read those systems, reach for them sparingly yourself.

$how it works
1

Traps intercept operations

new Proxy(target, { get(t, k) {...}, set(t, k, v) {...} }) hooks reads and writes around the target.

2

Reflect forwards defaults

Reflect.get/set perform the normal operation — traps validate then forward, customizing edges only.

3

Invariants limit lies

Non-configurable, non-writable properties must report truthfully — proxies can't fake the locked-down.

4

Frameworks use most

Reactivity systems and mocks lean on proxies; application code usually prefers plain validation.

$example
let user = new Proxy({ age: 30 }, {
set(t, k, v) {
if (k === "age" && v < 0) return false;
return Reflect.set(t, k, v);
},
});
user.age = -5;
console.log(user.age);
Output
30
1The set trap screens age assignments, rejecting negatives by returning false.
2-5 fails validation — the write never reaches the target (silent in sloppy, throws strict).
3age still reads 30 — validation enforced at the interception point.
$use cases
Validation layers rejecting bad writes centrally
Logging/tracing property access in debug builds
Revokable membranes cutting off shared objects
Reading framework reactivity (Vue, MobX) as proxy traps

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.