Facebook Pixel

What is the difference between microtask queue and macrotask queue?

Microtasks (Promise.then, queueMicrotask) are drained completely before each macrotask and before rendering. Macrotasks (setTimeout, events) run one at a time, with microtasks drained after each.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Call Stack vs Task Queue in JavaScript

The call stack runs synchronous code immediately, one frame at a time. The task queue (macrotask queue) holds callbacks from setTimeout and events, waiting to run when the stack is empty.

The Promise callback. Promise.then callbacks go to the microtask queue, which the event loop drains completely before touching the macrotask queue where setTimeout callbacks live.

Only when the call stack is empty. If a synchronous function is still running, queued callbacks wait, no matter how long the function takes.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

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.