Generator Function
Multiple Choice Medium
Question
What does a generator function return?
Hint
Generators yield values lazily.
Explanation
A generator function (function*) returns an iterator object when called. Each call to .next() runs the function until the next yield, returning {value, done}. Generators are useful for lazy sequences, custom iterators, and (historically) async control flow with co libraries. They can also be used with for...of loops.
Related Resources
Related Lessons
- Functions
Learn JS functions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.