What's the output: console.log + setTimeout + Promise + await?
Quick answer
Synchronous code first, then all microtasks (promises/await), then macrotasks (setTimeout).
In detail
Sync logs run first. `await`'s continuation and `.then` callbacks are microtasks, drained before any timer. So the timer logs last despite a 0ms delay.
1console.log("start");
2setTimeout(() => console.log("timeout"), 0);
3Promise.resolve().then(() => console.log("promise"));
4(async () => { console.log("async start"); await 0; console.log("async end"); })();
5console.log("end");
6// start, async start, end, promise, async end, timeoutWhy interviewers ask this: The output question that proves event-loop understanding.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299