Skip to content

OutputNot attempted

The first next() argument is ignored

function* ids(start = 0) {
let id = start;
while (true) yield id++;
}
const gen = ids(10);
console.log(gen.next(3).value);
console.log(gen.next(6).value);
console.log(gen.next().value);

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

Arguments to next() become the value of the PAUSED yield expression. The first next() starts the function, with no yield waiting to receive it, so 3 is dropped. Here the yields' results are never used anyway, so it just counts 10, 11, 12.