JS Built-ins
← Proxy14 / 100
Proxysetadvanced

Proxy set trap β€” returns true but does not store

πŸ“– Usage Example
const log = []
const p = new Proxy({}, {
  set: (t, k, v) => { log.push(String(k) + '=' + v); t[k] = v; return true }
})
p.x = 10
console.log(log) // β†’ ["x=10"]

The set trap intercepts property assignments on a proxy, letting you validate or observe writes before they reach the target.

set trap β€” return true without storing

A set trap can return true (indicating success) without actually writing to the target. The property will remain undefined.

Challenge: Verify that after p.n = 5, p.n is still undefined because the trap never stores the value.

πŸ’‘ Hints (1)
  • β€’ Returning `true` from `set` signals success but the trap controls whether the value is actually stored.