Difference between microtasks and macrotasks in JavaScript
Understand the difference between microtasks and macrotasks in the JavaScript event loop.
advancedAdvanced conceptsjavascriptevent loopasync
Published: 11/3/2025
Updated: 11/3/2025
Question
What’s the difference between microtasks and macrotasks in JavaScript?
Answer
The event loop handles tasks in two phases:
- Macrotasks: from callbacks like
setTimeout,setInterval,I/O. - Microtasks: from Promises,
queueMicrotask, and async/await resolution.
Order of execution:
- Execute one macrotask (main script)
- Run all queued microtasks before the next macrotask
setTimeout(() => console.log('Macrotask'), 0);
Promise.resolve().then(() => console.log('Microtask'));
console.log('Main');
// Output:
// Main
// Microtask
// Macrotask
Real-World Example
Understanding task queues helps debug React batching, async race conditions, and rendering delays.
Quick Practice
Predict output order for setTimeout, Promise, and queueMicrotask together.
Summary
Microtasks are prioritized — they always run before the next macrotask cycle.
Related Videos
Watch these videos to learn more about this topic
Frequently Asked Questions
Are Promises microtasks or macrotasks?
Promises are microtasks. setTimeout/setInterval are macrotasks.
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.