I'm preparing for mid–senior frontend interviews right now, and one pattern I keep seeing is this: people are "comfortable" with JavaScript, but the event loop exposes all the gaps. Here's a real‑style interview snippet I recently practiced: console.log("A"); setTimeout(() => { console.log("B"); }, 0); Promise.resolve() .then(() => { console.log("C"); }) .then(() => { console.log("D"); }); console.log("E"); Question: 1) What is the exact output order? 2) Why, in detail, does it execute in that order? Expected output: A → E → C → D → B In a mid/senior round, just giving the order isn't enough. You're expected to walk through: - Call stack vs Web APIs vs callback queue vs microtask queue. - Why Promise.then callbacks go into the microtask queue and run before setTimeout (macrotask) even with 0 ms delay. - How additional .then chains schedule new microtasks, which is why D still comes before B. How I'm using this for prep: - I rewrite similar snippets and force myself to explain the timeline step‑by‑step, as if on a whiteboard. - I then connect it to real bugs: spinners not hiding, state updates "lagging", or logs appearing in a "weird" order in React apps. If you're aiming for frontend roles where you'll touch React/Next.js daily, this depth on the JS event loop is no longer "nice to have" – it's a baseline expectation. 💡 If you want, I can share a full Google Doc of 20+ event‑loop style questions (with answers) that I'm using for my own interview prep. Comment "EVENT LOOP" and I'll send it over. #frontend #javascript #eventloop #webdevelopment #reactjs #nextjs #frontendinterview #techcareers #indiadevelopers
EVENT LOOP
A → E → C → D → B