Why it is not 0 1 2 3 4 5? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Why it is not 0 1 2 3 4 5?

Why not 0 1 2 3 4 5 https://code.sololearn.com/W9NpIZA4ftt8/?ref=app

4th May 2019, 8:40 AM
Sławek J.
4 Answers
+ 4
Because i is getting incrementet so fast that after the waiting time of 1000*i miliseconds i has the value 6. And so it only prints 6.
4th May 2019, 8:46 AM
Dragonxiv
Dragonxiv - avatar
+ 2
1 It is post increment. var i 2 The timeout never occurred 3 The Max of var i is 5 4 I++ = 6 5 loop prints 6 six times 🤗
4th May 2019, 9:52 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
U may need async and await
4th May 2019, 12:19 PM
AMANULLAH
AMANULLAH - avatar
0
Trying to understand this.. In part A of the code, the values are logged as expected but can't see the time delay.. In part B, there is overall delay of 5 sec but prints values correctly in for loop not when called using set timeout function.. Also why the behaviour changes when the function takes parameter/argument.. https://code.sololearn.com/WX6GVnTf5odf/?ref=app
5th May 2019, 11:40 AM
Aravazhi