setTimeout( ) inside a loop - JavaScript Tutorial

Published: 25 July 2021
on channel: stepUP
498
7

#Shorts

👉For each loop, the setTimeout must create an execution context for the method setTimeout(). As loop iterated 5 times, so there are 5 execution context created ( each with one setTimeout() ). So once loop ended, the value for i = 5 ( as last statement is i++ ). The execution state for the for loop popped out now.

👉Now for each setTimeout() ( pushed 5 times in the execution context ), invoked after 1 second with a console.log(i). What's the value for i now? i is global here so, value will be 5.

#javascript
#javascripttutorial
#javascriptforbeginners
#javascripttips
#javascripttricks
#javascriptloop
#loop
#setTimeout



----------
🎶
When you are using this track, please put this in your description:

Track: A Himitsu - Adventures [NCS Fanmade]
Music provided by Audio Library    • Adventures – A Himitsu (No Copyright Music)  
Music released by Argofox    • A Himitsu - Adventures [Royalty Free Music]  
Download / Stream: https://goo.gl/zzsgxy
Link to this video:    • A Himitsu - Adventures [NCS Fanmade]   (optional)


On this page of the site you can watch the video online setTimeout( ) inside a loop - JavaScript Tutorial with a duration of hours minute second in good quality, which was uploaded by the user stepUP 25 July 2021, share the link with friends and acquaintances, this video has already been watched 498 times on youtube and it was liked by 7 viewers. Enjoy your viewing!