$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #39

What is logged?

for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0);
}
  1. 0 1 2
  2. 0 0 0
  3. 1 2 3
  4. 3 3 3
var is function-scoped, so all callbacks see the final i of 3.
Play Problem Solving ▸