Facebook Pixel

Can microtasks starve macrotasks in JavaScript?

Yes. If a microtask keeps adding more microtasks (recursive Promise.then), the event loop never reaches the macrotask queue. setTimeout callbacks never run. The page freezes. This is called microtask starvation.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in The Event Loop in JavaScript: A Complete Explanation

A mechanism that continuously checks if the call stack is empty. If it is, it drains all microtasks (promise callbacks), then takes one macrotask (setTimeout, events). This repeats forever, allowing async callbacks to run on the single-threaded engine.

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

Because promise callbacks go to the microtask queue, which the event loop drains completely before touching the macrotask queue where setTimeout callbacks live. Even with 0 delay, the timer waits for microtasks.

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.