Your Callback Printed 3, 3, 3: JavaScript Closures Capture the Variable, Not the Value
This loop is supposed to log 0, 1, 2:
const out = [];
for (var i = 0; i < 3; i++) setTimeout(() => out.push(i), 0);
// later: out is [3, 3, 3]
Swap var for let and you get [0, 1, 2]. Most explanation