freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #14 of 61

object methods · assign · freeze · seal

LambdaVSThe Mutator
Lambda saysObject.assign copies properties; Object.freeze and seal lock an object down.

Object.assign(target, ...sources) copies enumerable props (a shallow merge). Object.freeze(obj) makes it fully immutable (no add/change/delete); Object.seal(obj) allows changing existing values but no adding/removing. Freeze is shallow — nested objects stay mutable.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleFreeze an object, try to change a property (no effect), then merge two with spread.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const o=Object.freeze({x:1}); o.x=99; const merged={...{a:1},...{b:2}};
document.getElementById('o').textContent='frozen x='+o.x+' merged='+JSON.stringify(merged);</script></body></html>
▶ Open the interactive comic issue
‹ Object Methods · Keys · Values · EntriesSpread On Objects · Merging ›