JavaScript Interview Question: Output of setTimeout Loop

💻 JavaScript Interview Question What will be the output of the following code? for (var i = 1; i <= 3; i++) { setTimeout(function() { console.log(i); }, 1000); } 🤔 Think before you answer! Options: A) 1 2 3 B) 3 3 3 C) 4 4 4 D) Error 💡 Bonus Question: How would you modify the code so it prints 1 2 3 instead? 👇 Comment your answer. If you are preparing for JavaScript or frontend interviews, I regularly share interview questions and also conduct mock interview sessions through devCareer mentor to help candidates gain confidence. #JavaScript #FrontendInterview #CodingInterview #CareerGrowth #MockInterview

To view or add a comment, sign in

Explore content categories