Back to results for “Concurrency”
JavaScript › Event Loop & Concurrency

What is the difference between the microtask queue and the macrotask (task) queue?

Intermediate

Answer

Promise callbacks (.then, async/await continuations) go into the microtask queue, which is fully drained after every single macrotask completes. setTimeout, setInterval, and I/O callbacks go into the macrotask queue, processed one at a time between event loop ticks.
console.log('1');
setTimeout(() => console.log('2 (macrotask)'), 0);
Promise.resolve().then(() => console.log('3 (microtask)'));
console.log('4');
// logs: 1, 4, 3, 2
Real-world example Understanding why a Promise callback always runs before a setTimeout(fn, 0), even though both are 'async'.

Common follow-ups: What happens if a microtask queues another microtask — does it get processed in the same cycle?