Iterable protocol and for...of
Learn the iterable protocol: Symbol.iterator, iterator.next(), and using for...of, spread, and Array.from with small custom examples.
Big picture
Goal: Read and build tiny iterables.
- What iterable means
- Symbol.iterator and iterator.next()
- for...of, spread, Array.from
- Build a 0..N counter example

for...of on built-ins
for...of works on built-in iterables like arrays and strings, yielding items in order.
// Arrays and strings are iterable
const arr = [10, 20, 30];
for (const n of arr) {
console.log("arr item:", n);
}
const word = "JS";
for (const ch of word) {
console.log("char:", ch);
}

All lessons in this course
- Iterable protocol and for...of
- Generator functions, yield, and small pipelines
- Async iterators — for await...of and async generators