Generators & Iterators — Free JavaScript Tutorial
Learn Generators & Iterators in JavaScript with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Generators & Iterators in JavaScript with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Generators & Iterators in JavaScript
Iterators: Objects with a `next()` method that returns `{value, done}`. Arrays, strings, Maps, Sets are all iterables.
Generators (`function*`): Functions that can be paused and resumed. `yield` pauses and returns a value. Calling the generator returns an iterator.
Use cases: Lazy evaluation, infinite sequences, async flow control, custom iterables.
`yield*` delegates to another iterable. Can receive values sent in via `generator.next(value)`.
Learn Generators & Iterators step by step with Syllab's free interactive JavaScript tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full JavaScript course →