Lesson content
Read, practise, then check your understanding
Calling a generator function returns an iterator without running the full body. Each next resumes until yield or completion.
Lazy values
function* range(start, end) {
for (let value = start; value < end; value += 1) yield value;
}
for (const value of range(1, 4)) console.log(value);
yield* delegates to another iterable. Values passed to next(value) become the previous yield expression’s result, enabling two-way protocols, while return completes iteration. Generators simplify lazy/infinite sequences and traversal state but must still release resources when consumers stop; use try/finally when cleanup matters.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.