Skip to main content

What are microtasks and macrotasks in the Node.js event loop?

Mid NodeJS
Quick Answer Microtasks (Promise callbacks, queueMicrotask) run before the event loop moves to the next phase รขโ‚ฌโ€ they drain completely between each event loop tick. Macrotasks (setTimeout, setInterval, I/O callbacks) are picked up one at a time per event loop iteration. Microtasks have higher priority รขโ‚ฌโ€ a Promise chain can delay macrotasks if it keeps adding more microtasks.

Answer

Microtasks include promise callbacks and queueMicrotask. Macrotasks include timers, I/O callbacks, and setImmediate. Microtasks run before macrotasks within each event loop cycle.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice