0Pricing
JavaScript Academy · Lesson

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

  1. Creating Unique Symbols
  2. Symbols as Object Keys
  3. The Global Symbol Registry
  4. Well-Known Symbols
← Back to JavaScript Academy