ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What's the difference between microtasks and macrotasks?

Quick answer

Microtasks (promise callbacks) drain completely after each macrotask (setTimeout, I/O, events). Microtasks always run first.

In detail

After each macrotask the engine empties the entire microtask queue before rendering or taking the next macrotask. So `.then`/`await` continuations and `queueMicrotask` run before any `setTimeout`, even a 0ms one.

console.log(1);
setTimeout(() => console.log(2));        // macrotask
Promise.resolve().then(() => console.log(3)); // microtask
console.log(4);
// 1 4 3 2

Why interviewers ask this: The follow-up that confirms true event-loop depth.

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

Full kit

JavaScript Interview Kit · ₹299

Get it →