Javascript
Apr 24, 2026
What does g.next().value print twice?
function* gen() {
yield 1
yield 2
yield 3
}
const g = gen()
console.log(g.next().value)
console.log(g.next().value)
Explanation
Generators pause at each yield. Each .next() resumes until the next yield.
📝
Reviewed by CodeShot Editorial
Every challenge is code-reviewed by senior developers to ensure accuracy and real-world relevance. Learn more.