What does this log when you break out of a loop over a generator and then reuse it?
function* numbers() {
try {
yield 1;
yield 2;
yield 3;
} finally {
console.log("cleanup");
}
}
const it = numbers();
for (const n of it) {
console.log(n);
if (n === 2) break;
}
console.log([...it]);
const [first] = numbers();
console.log(first);
The answer
Work out every line it logs, in order. Then check.
Checking your sign-in…