You should probably also mention that
for (let i = 1; i <= 3; i ++) setTimeout(() => console.log(i), 100);
gets you 1 2 3, whereas
1 2 3
for (var i = 1; i <= 3; i ++) setTimeout(() => console.log(i), 100);
will output 4 4 4. IMO this is one of the major reason why scope of loop variable matters.
4 4 4
Some comments have been hidden by the post's author - find out more
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You should probably also mention that
gets you
1 2 3
, whereaswill output
4 4 4
. IMO this is one of the major reason why scope of loop variable matters.