Question #39

Author: admin
tags: JavaScript  
function * myGen() {
  yield 1;
  yield 2;
  yield 3;
}

const gen = myGen();

console.log(gen.next());
console.log(gen.next());
console.log(gen.next()); // ??
What will the console display on the line marked with two question marks?
{ value: 3, done: false }
{ value: 3, done: true }
3
Nothing, there is an error in the code.
The yield operator will return an object that has the property done: false, even if this is the last yield.
You need to call the next() method again to get the object with done: true property.
Rate the difficulty of the question:
easyhard