🚀 JavaScript Interview Challenge: Can you guess the output? Let’s test your understanding of Event Loop, Microtasks and Async/Await 👇 Code snippet -> console.log('1'); setTimeout(() => { console.log('2'); }, 0); Promise.resolve().then(() => { console.log('3'); }); (async function() { console.log('4'); await Promise.resolve(); console.log('5'); })(); console.log('6'); Before scrolling down, take 10 seconds and think - What do you think will be printed in the console (and in what order)? Drop your answer in the comments 👇 ⚙️ Let’s understand step-by-step: 1️⃣ console.log('1') → runs immediately (synchronous) 2️⃣ setTimeout(...) → goes to the macro task queue 3️⃣ Promise.resolve().then(...) → goes to the microtask queue 4️⃣ Inside the async IIFE: 🔹console.log('4') → runs immediately 🔹await Promise.resolve() → pauses here; the continuation (console.log('5')) goes to microtask queue 5️⃣ console.log('6') → runs next (still in sync phase) Now, the synchronous part is done. Next, the microtasks (Promises, async/await continuations) run: ➡️ '3' ➡️ '5' Finally, macro task (from setTimeout) runs: ➡️ '2' 💬 Comment below 👇 Did you get this right on your first try? Or were you surprised by where '3' and '5' appeared? If you love understanding how JavaScript actually works under the hood, follow me for more such bite-sized explanations ⚡ #JavaScript #WebDevelopment #AsyncJS #Frontend #CodingChallenge #LearnInPublic #AkshayPai #JavaScriptConsoleOutput #JavaScriptInterview #LearnJavaScript #Developer #Reactjs #Nodejs #Angular #TypeScript
solved at first! no job yet 💀
You could add another file called Worker.js to add more complexity. Asked me in one of the interview