A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-80.js
1varfns=[];
2for(vari=0;i<3;i++){fns.push(()=>i);}
3console.log(fns.map(f=>f()).join(","));
Scope
Answer & explanation
Console output
3,3,3
Why
A var declaration is function-scoped, so the loop creates a single binding i that all three closures capture by reference. The functions are not called until after the loop ends, at which point i has been incremented to 3, so every closure logs 3. Switching to let would give each iteration its own fresh binding.