π INDEX
LOADING ENGINE...
JS Generators
Pause execution, yield values, and master asynchronous flows.
generator.js
βοΈ
Generator Suspending...
ADA:Generators are special functions that can be paused and resumed. They are defined with 'function*'.
Core Concepts
Generators do not execute their body immediately when called. Instead, they return an Iterator object.
function* counter() {
yield 1;
yield 2;
return 3;
}Memory Probe
What does a generator function return when first invoked?
Practical Usage
- 01.Infinite Sequences: Create sequences like Fibonacci without crashing the browser memory.
- 02.Custom Iterables: Make objects iterable with the [Symbol.iterator] property.
- 03.Async/Await Polling: Control complex state machines or retry logic easily.
Developer Badges
βοΈ
The Iterator
Successfully defined a function* with a yield statement.
βΈοΈ
Pause & Play
Understand the lifecycle of a suspended generator.
π§
State Wizard
Mastered data passing into .next() calls.
Glossary: Generator Protocol
- next()
- The method used to resume execution. It returns an object: { value: any, done: boolean }.
- yield*
- Used to delegate to another generator or iterable (nesting generators).