Well-Known Symbols: Hooking into Built-ins

Rohim’s piggy bank at the counter: a spread calls [Symbol.iterator]() then next() until done, + gives toPrimitive the hint 'default', toString reads…

Why it matters

This is how the built-in Array, Map, Set and strings "understand" the language’s syntax. When you build your own collection that works with for...of, a money type that turns into a number or a text safely, or an object whose name prints neatly in a log, you put these Symbols on it.

The key idea

A well-known symbol is an official hook the language calls

Common mistakes

Try it in this playground