Symbols in JavaScript
Symbols (Symbol("desc")) are guaranteed-unique identifiers — every call creates a value unequal to all others, including identically-described ones. Their job is collision-free property keys: library internals, framework hooks, and well-known protocol slots (Symbol.iterator, Symbol.toPrimitive) that user code can never accidentally clash with.
Symbols stay invisible to normal enumeration (Object.keys skips them; JSON.stringify drops them) and require computed access (obj[sym], never obj.sym). Use them for framework-level extension points and truly private-ish keys — not everyday identifiers.
Unique every time
Symbol("id") !== Symbol("id") — descriptions label for debugging only; uniqueness is structural.
Collision-free keys
obj[Symbol("x")] = 1 can never clash with string keys or other symbols — libraries extend shared objects safely.
Invisible by default
Skipped by Object.keys, for...in, spread, and JSON — reach them via Object.getOwnPropertySymbols when needed.
Well-known protocols
Symbol.iterator, Symbol.toPrimitive, Symbol.hasInstance let classes hook iteration, conversion, and instanceof.
let id = Symbol("id");let user = { name: "Ada", [id]: 7 };console.log(user[id], Object.keys(user).length);Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.