Hint
function* that can yield values lazily; returns an iterator
Generators (function*) can pause execution and yield values one at a time.
function* range(start, end) {
for (let i = start; i <= end; i++) yield i;
}
for (const num of range(1, 5)) console.log(num); // 1,2,3,4,5
// Infinite lazy sequence
function* naturals() {
let n = 0;
while (true) yield n++;
}
Use cases: lazy/infinite sequences, custom iterators, Redux-Saga uses generators for async flows.