Q30: How do Generators and Iterators work in JavaScript?
An Iterator is an object with a next() method returning { value, done }. Generators (function*) are special functions that can pause execution using yield and resume when next() is called on their returned Generator object.
Key Takeaways
yieldpauses generator functions and returns execution values.- Generators implement the iterable protocol automatically.
Knowledge Check
Which keyword pauses execution inside a Generator function?