JS Quiz: Hard: Generator consumption order puzzle

What is logged?

function* g() {
  yield 1;
  yield 2;
  return 3;
}
const it = g();
const a = [...it];
const b = it.next();
console.log(a.join(','), b.value, b.done);
  • 1,2,3 3 true
  • 1,2 undefined true
  • 1,2 3 false
  • 1,2 undefined false
0 voters

WaffleFries :smiling_face_with_sunglasses:

When you do const a = [. . . it], does the spread ever include the generator’s return 3 value, or does it stop at the last yield and leave it. next() to come back as { value: undefined, done: true }? I might be wrong here.