- Tutorials
- JavaScript Tutorial
- JavaScript Generators & Iterators
JavaScript Generators & Iterators
7 lessonsAbout 42 minutesAdvanced
This part of the JavaScript Tutorial runs from JavaScript Iterators through to JavaScript Async Iteration. There are 7 lessons here, and working through them takes about 42 minutes at a steady pace.
It follows on from JavaScript Modules, so finish that first if you have not already — the examples below assume you are comfortable with it.
Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.
- 1JavaScript IteratorsAn iterator is an object with a next method that hands out one value at a time.
- 2JavaScript IterablesAn iterable is anything with a Symbol.iterator method, which is what for...of actually looks for.
- 3JavaScript Generator FunctionsA generator function can pause with yield and resume later, producing one value at a time.
- 4JavaScript Generator CommunicationValues can be sent into a running generator through next, not just read out of it.
- 5JavaScript Custom IterablesAdding a Symbol.iterator method makes your own object work with for...of.
- 6JavaScript Lazy SequencesA generator can represent a sequence that has no end, because it only computes what is asked for.
- 7JavaScript Async Iterationfor await of loops over values that arrive one at a time, each behind a promise.
