Hint
Generators are lazy: code only runs when you call next(). Each yield is a pause point. The generator resumes exactly where it left off.
function* gen() {
console.log('A');
yield 1;
console.log('B');
yield 2;
console.log('C');
}
const g = gen();
console.log(g.next().value);
console.log(g.next().value);
console.log(g.next().done);A 1 B 2 C true
Explanation: gen() does NOT run yet β just creates the iterator. First next(): runs until yield 1, logs A, returns {value:1}. Second next(): resumes, logs B, returns {value:2}. Third next(): resumes, logs C, hits end, returns {done:true}.
Key Insight: Generators are lazy: code only runs when you call next(). Each yield is a pause point. The generator resumes exactly where it left off.