Generators & Iterators
HardIn plain terms
function* yields values. next() returns { value, done }. Used for lazy sequences, async iteration. yield pauses; next() resumes.
What you need to know
- •function*
- •yield
- •Iterator protocol
Try it yourself
Copy the code below and run it in your browser console or a code editor:
function* gen() { yield 1; yield 2; } const g = gen(); g.next(); // { value: 1, done: false }Learn more
Dive deeper with these trusted resources: