Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaScriptcustom iterables Symbol.iteratorSingle-choice MCQ

A generator function is itself iterable. Why does calling `[...gen]` directly on the generator FUNCTION (not its result) throw, while `[...gen()]` works?

function* gen() { yield 1; yield 2; } console.log([...gen()]);