Facebook Pixel
Microtask Queue vs Macrotask Queue in JavaScript

What goes in the microtask queue in JavaScript?

The answer

Promise.then, .catch, .finally callbacks, queueMicrotask(fn), MutationObserver callbacks, and process.nextTick (Node.js, even higher priority than promises).

More FAQs in Microtask Queue vs Macrotask Queue in JavaScript

Microtasks (Promise.then, queueMicrotask) are drained completely before any macrotask and before rendering. Macrotasks (setTimeout, events, I/O) run one at a time with microtasks drained after each. Microtasks have higher priority.

Because promise callbacks go to the microtask queue, which the event loop drains completely before taking any macrotask from the macrotask queue where setTimeout callbacks live. Microtasks always run first.

setTimeout, setInterval, setImmediate (Node.js), I/O callbacks (network, file system), UI events (click, input, scroll), MessageChannel, and postMessage callbacks.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.