Leaderboard Archive
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)
A 1, 1
B 1, 2
C undefined, undefined
D 1, undefined
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.

Ready for your shot?

Join thousands of developers solving one logic puzzle every morning.

Solve Today's Challenge →