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.
@shagunjaiswal340311 ай бұрын
video se jada acha tummhare code ne samjha diya
@RajYadav-yh7vv2 жыл бұрын
worst incomplete poor explanation of event loop and bro toda normal raho aur dialogue toda kam kiya karo
@parth14502 жыл бұрын
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 👍
@careerwithgaurav2 жыл бұрын
Hi, Sure have noted dow will make video on this again soon in JS series for beginners which is currently in progress.
@buggplayer2301 Жыл бұрын
true and lesss content and more promotion
@animeshdey62892 жыл бұрын
Callstack works on LIFO not FIFO
@BhaveshBarskar Жыл бұрын
another way to get desired result is to - change var to let it will print 0,1,2
@jagadishprasad4142 Жыл бұрын
not working, throwing error while executing online jscompiler
@techupdate032 жыл бұрын
Use let instead of var.. output will be 0,1,2
@FreeSkypeGenerator12 жыл бұрын
thanks for the pointer
@mohakmaheshwari87562 жыл бұрын
interviewers don't let you change it two let and const , self calling function is the only way
@jagadishprasad4142 Жыл бұрын
for(var i=0; i
@bromptonhorsing85972 жыл бұрын
Why do you use English title and then speak another language in the video?
@mohakmaheshwari87562 жыл бұрын
two times i got this function that fucked up my interview
@fatimaiqra21694 ай бұрын
thanks
@PURRAHARAAMI2 жыл бұрын
kya smjhaya bhai tune??? kuch smjh nhi ayaa
@ambupadamuduli37943 жыл бұрын
Thanks for this.we want more questions like this
@misterl81293 жыл бұрын
damn, dont understand the language
@imkir4n Жыл бұрын
u earned my sub,thank u
@ArnavSingh-im5bj3 ай бұрын
Or you can use let
@RohitSharma-iq8ne3 жыл бұрын
sir var ki jgh let krne pr 012 answer kiyo a rha he
@BhaveshBarskar Жыл бұрын
because "let" keyword is blocked scoped, so for every iteration value of new copy of i is passed to closure function i.e setTimeout().
@ravikumarchaudhari16062 жыл бұрын
thank you for this osm video
@sachinsharma17552 жыл бұрын
bhai interviewer kya sochega usse chodo wo btao jo tum soch rha hao, uske dimaag mai rhen do ki wo kya puchega