i < 5 (5 < 5) is FALSE then we stop executing the loop
At the end of the loop i = 5 (not 4). The loop repeated 5 times (i = 0,1,2,3,4).
When setTimeout starts to execute the function it uses the global "i", which is 5, and executes it 5 times hence you see "5" five times.
UPD: replaced "let" by "var". Copied from the wrong place. There are no issues with "let".
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.
Hey, can you please explain no 2 more? Why will it be all 5
Let's first understand how the loop works.
At the end of the loop i = 5 (not 4). The loop repeated 5 times (i = 0,1,2,3,4).
When setTimeout starts to execute the function it uses the global "i", which is 5, and executes it 5 times hence you see "5" five times.
UPD: replaced "let" by "var". Copied from the wrong place. There are no issues with "let".