Well-Known Symbols
Customize behavior with Symbol.iterator and others.
Well-Known Symbols
Well-known symbols are built-in symbols stored on the Symbol object. They let you customize how objects behave with language features like iteration and conversion.
console.log(typeof Symbol.iterator)
console.log(typeof Symbol.toPrimitive)Symbol.iterator
Symbol.iterator defines how an object is iterated by a for-of loop and the spread operator. Built-in arrays and strings already provide it.
const arr = [10, 20]
const it = arr[Symbol.iterator]()
console.log(it.next().value)All lessons in this course
- Creating Unique Symbols
- Symbols as Object Keys
- The Global Symbol Registry
- Well-Known Symbols