Skip to content

FlashcardNot attempted

Iterator pattern

Recall it before you reveal

What is the Iterator pattern, and how does JavaScript build it in?

Space to reveal
Show answer & explanation

It gives one uniform way to traverse a collection without exposing how it's stored. JS bakes it in through the iterator protocol: [Symbol.iterator]() returning { next() → { value, done } }. Generators implement it for you.

Because of it, for...of, spread, destructuring and Array.from work the same on arrays, Maps, Sets, strings, NodeLists, and your own trees or ranges.