filmov
tv
Javascript Quiz: How Well Do You Know setTimeout function in JS#programming #javascript #coding#quiz

Показать описание
Are you ready for another code challenge? Join me in this video as you test your coding knowledge with the simple quiz questions.
Don't forget to make your guess in the comments below.
-------------------------------------------------------------------------------------------
🔔Like and subscribe for more videos. 🔔
Connect me on linkedin :
------------------------------------------------------------------------------------------
Answer OPTION: C) 5 5 5 5 5
Explanation:
This code demonstrates a common misconception related to JavaScript closures. The setTimeout function runs asynchronously, and by the time the callback function is executed, the loop has already completed. The variable i is declared using the var keyword, which creates a single variable shared across all iterations.
Hence, when the callbacks are invoked, the value of i is already 5 for all of them.
Don't forget to make your guess in the comments below.
-------------------------------------------------------------------------------------------
🔔Like and subscribe for more videos. 🔔
Connect me on linkedin :
------------------------------------------------------------------------------------------
Answer OPTION: C) 5 5 5 5 5
Explanation:
This code demonstrates a common misconception related to JavaScript closures. The setTimeout function runs asynchronously, and by the time the callback function is executed, the loop has already completed. The variable i is declared using the var keyword, which creates a single variable shared across all iterations.
Hence, when the callbacks are invoked, the value of i is already 5 for all of them.