JavaScript

What are generator functions?

Hard
4
Added
Functions that can pause/resume execution using yield. Return iterator object.

Solution Code

JavaScript
function* gen() { yield 1; yield 2; }
const g = gen();
Explanation
Used for lazy evaluation and async operations before async/await.

Guided Hints

Implement infinite sequence
Compare with async/await