Advanced JavaScript / Generators
Generators
A function that can pause mid-execution with yield, and resume exactly where it left off.
A generator function (`function*`) doesn't run to completion when called — it returns an iterator instead. Each call to `.next()` runs the generator until the next `yield`, hands back that value, and freezes the function's entire state — local variables, position, everything — until `.next()` is called again.
Codeeditable — Run executes your edits
Loading...
Console
Output will appear here
Visualization
State
Step through — the console panel shows what's happening
Why?
Calling numbers() doesn't execute the body at all — it just creates a paused generator. Each next() resumes execution up to the following yield, then pauses again.