Rohim’s piggy bank at the counter: a spread calls [Symbol.iterator]() then next() until done, + gives toPrimitive the hint 'default', toString reads…
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.
A well-known symbol is an official hook the language calls
iterator() method, yet for...of still fails The key must be [Symbol.iterator] (a computed key with the real Symbol), not the text 'iterator'. A method under that text name is just a plain property the engine never calls.Symbol.iterator be a generator? No: it only has to return an iterator, an object with a next() method giving { value, done }. The piggy bank here uses just such a plain object. A generator (*[Symbol.iterator]()) is only the shortest way to make one.obj + 1 is wrong even though Symbol.toPrimitive is in place + gives the hint 'default', not 'number'. Check all three: 'number', 'string' and 'default', and decide what to give for 'default'.'iterator' The engine does not call it: a TypeError.celengan + 1 and ` ${celengan} `.