Async + Closures Challenge: What happens first?

🚀 Output Challenge #2 — Async + Closures Edition Most developers think they know JavaScript, until setTimeout and var walk into the room together 😅 Here’s your next test 👇 for (var i = 1; i <= 3; i++) { setTimeout(() => console.log(i), i * 1000); } console.log("Loop complete"); 🧠 Before you scroll — think: What happens first? What gets logged and when? Why is this a classic interview trap? 💬 Drop your output + reasoning in the comments 👇 Let’s see who really understands the event loop 🔄 No console, no AI, just your JS brain🧩 #JavaScript #Frontend #WebDevelopment #React #Nextjs #CleanCode #Async #Closures #MachineCodingRound #InterviewPreparation #DeveloperCommunity

Synchronous code runs first so Loop complete 4 4 4 var is function scoped same i shared and till the time that callback executes the loop has finished with i = 4.

See more comments

To view or add a comment, sign in

Explore content categories