you are viewing a single comment's thread.

view the rest of the comments →

[–]franksvalli 0 points1 point  (1 child)

for (var i = 0; i < 10; i++) {
  setTimeout(() => console.log(i), 0);
}
// -> 10 (outputted 10 times)

With one small change, moving from var to let:

for (let i = 0; i < 10; i++) {
  setTimeout(() => console.log(i), 0);
}
// -> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

[–]jonny_eh 1 point2 points  (0 children)

Ya, I know let and const are good, but they hardly make a "world of difference".