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

symbols · unique keys

LambdaVSThe Mutator
Lambda saysSymbols are unique, immutable values used as collision-proof object keys.

Symbol("desc") creates a value guaranteed unique — even two symbols with the same description differ. Used as object keys, they never clash with string keys or each other, so libraries use them for "hidden" metadata. Well-known symbols (Symbol.iterator) hook into language behavior.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleUse a Symbol as an object key and confirm it does not collide with a string key.

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 id=Symbol('id'); const o={[id]:42, id:'string key'};
document.getElementById('o').textContent='symbol='+o[id]+' string='+o.id;</script></body></html>
▶ Open the interactive comic issue
‹ Prototypes · The Old InheritanceMap · Ordered Key-Value Store ›