← Back to archive

Stdle #125 · async · 2026-10-03

What does this JavaScript snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

const it = {
data: [1, 2, 3],
pos: 0,
next() { return this.pos < this.data.length ? { value: this.data[this.pos++], done: false } : { value: undefined, done: true }; },
[Symbol.iterator]() { return this; },
};
let sum = 0;
for (const n of it) sum += n;
console.log(sum);
Async
4 attempts left

Answer & explanation