microtask
A microtask is a short job that runs as soon as the current script or callback finishes and the call stack is empty, before the event loop moves on to the next timer, I/O, or event callback.
Promise callbacks are the most common microtasks. When a promise settles, each .then() handler waits in the microtask queue, and code after await resumes the same way. The global queueMicrotask() function, which browsers and Node.js provide, adds a callback to that queue directly.
The event loop drains the whole queue at once. A microtask that queues another microtask still runs before any timer callback, so an endless chain of them starves timers and, in browsers, rendering.
ECMA-262 calls these units of work promise jobs and requires them to run in the order they were queued. The WHATWG HTML Standard defines the microtask queue that browsers run them from, and Node.js runs them from a microtask queue of its own.
Example
Say an order form starts a zero-millisecond timer to show a spinner, then saves the order in an async function with two awaited steps. The program shows when each part runs:
save-order.mjs
setTimeout(() => {
console.log("Timer: show spinner");
}, 0);
async function saveOrder() {
console.log("Validate order");
await null;
console.log("Save order");
await null;
console.log("Send receipt");
}
saveOrder();
console.log("Script done");
Running the file prints the spinner line last:
$ node save-order.mjs
Validate order
Script done
Save order
Send receipt
Timer: show spinner
Each await pauses saveOrder() and queues its next step as a microtask. The second step is queued while the queue is already draining, yet it still runs before the timer callback, which has to wait until no microtasks are left.
Step through the program to watch each await queue a microtask and the timer callback wait its turn:
Related Resources
Course
The JavaScript Event Loop, Concurrency, and Workers
Build a weather-station dashboard in JavaScript, and learn how the event loop orders timers and promises, how to cancel work with AbortController, and when to move CPU work to a worker.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 16, 2026