Those who are trying to understand this might help: the for loop will complete all iterations before any of the setTimeout functions are executed because setTimeout is an asynchronous function . As a result, the value logged for i in all three iterations will be 3. if we change var to let, output will be 0,1,2 because in case of let a new block scope is created for each iteration of the loop. This means that each iteration of the loop will have its own separate lexical environment and its own distinct value whereas in case of var, it does not create a new block scope, there is only one i variable shared across all iterations of the loop as var is function scoped.
I am still waiting for your exact explanation.. Bhai tho slow details me bana do video..tho acha hoga .. Ye video kab shuru hoke khatm hua pata hi nai chala.. This is genuine feedback don't take it otherwise 👍
Those who are trying to understand this might help:
the for loop will complete all iterations before any of the setTimeout functions are executed because setTimeout is an asynchronous function . As a result, the value logged for i in all three iterations will be 3.
if we change var to let, output will be 0,1,2
because in case of let a new block scope is created for each iteration of the loop. This means that each iteration of the loop will have its own separate lexical environment and its own distinct value whereas in case of var, it does not create a new block scope, there is only one i variable shared across all iterations of the loop as var is function scoped.
video se jada acha tummhare code ne samjha diya
worst incomplete poor explanation of event loop and bro toda normal raho aur dialogue toda kam kiya karo
I am still waiting for your exact explanation..
Bhai tho slow details me bana do video..tho acha hoga ..
Ye video kab shuru hoke khatm hua pata hi nai chala..
This is genuine feedback don't take it otherwise 👍
Hi, Sure have noted dow will make video on this again soon in JS series for beginners which is currently in progress.
true and lesss content and more promotion
Callstack works on LIFO not FIFO
another way to get desired result is to - change var to let it will print 0,1,2
thanks
not working, throwing error while executing online jscompiler
u earned my sub,thank u
for(var i=0; i
Thanks for this.we want more questions like this
thank you for this osm video
Use let instead of var.. output will be 0,1,2
thanks for the pointer
interviewers don't let you change it two let and const , self calling function is the only way
Or you can use let
two times i got this function that fucked up my interview
Why do you use English title and then speak another language in the video?
thanks sir
kya smjhaya bhai tune??? kuch smjh nhi ayaa
sir var ki jgh let krne pr 012 answer kiyo a rha he
because "let" keyword is blocked scoped, so for every iteration value of new copy of i is passed to closure function i.e setTimeout().
damn, dont understand the language
1 question answer is 333
Bhai kya bolna chaha raa hai? Jaldi Bol Kal Subah Panvel Nikalna Hai...
bhai interviewer kya sochega usse chodo wo btao jo tum soch rha hao, uske dimaag mai rhen do ki wo kya puchega
😂😂
3
Galat maat batao bhai its discouraging!!
Abe mere bhai explain toh kya bakwaas youtuber hai
10min waste kr die mere
not a good explaination
Rude..