All topics
ES6+advanced

Well-Known Symbols and Symbol.iterator

The set of built-in Symbol values that let user code hook into and customize core language behaviors like iteration, type coercion, and instanceof checks.

Well-known symbols are a fixed set of built-in Symbol values, defined directly on the Symbol constructor, that JavaScript itself uses internally as extension points, letting your own objects hook into and customize behaviors the language otherwise handles automatically. This is a genuinely advanced topic that separates candidates who deeply understand JavaScript's object model from those who've only used its surface-level features.

Well-known symbols are like universal remote-control buttons built into every device: if an appliance chooses to wire up the volume button to its own custom behavior, the remote automatically uses that wiring instead of doing nothing.

Key Concepts

1
Symbol.iterator, covered under the iterable protocol, is the most common well-known symbol: defining a [Symbol.iterator]() method is what makes an object work with for...of and spread. Symbol.toPrimitive lets an object customize how it converts to a primitive value in different contexts ('number', 'string', or 'default') — implementing it on a class lets a custom Money or Temperature object behave sensibly in arithmetic or string contexts.
2
Symbol.hasInstance lets you customize what instanceof actually checks, overriding the default prototype-chain walk — useful for duck-typing-style instance checks. Symbol.toStringTag customizes the string returned by Object.prototype.toString.call(obj), useful for giving custom classes a descriptive type tag.
3
The unifying theme is that well-known symbols are the sanctioned mechanism for opting into custom behavior for operations otherwise fixed by the language, and because they're actual Symbol values, there's no risk of colliding with a regular property name.