macrotask
A macrotask is a unit of work, such as a timer callback or an event handler, that the event loop runs one at a time, and the loop runs all pending microtasks before it starts the next one.
The word is informal. The WHATWG HTML Standard, which defines the event loop in browsers, calls these units tasks and keeps them in task queues, so “task queue” is another name for where macrotasks wait. The term exists to set them apart from microtasks, such as promise callbacks.
Running a script, dispatching a click event, and calling a setTimeout() or setInterval() callback are all macrotasks. In each turn, the event loop takes one macrotask, runs it until the call stack is empty, and then drains the microtask queue. Only then does it pick the next macrotask, and browsers may render in that gap.
ECMA-262 doesn’t define macrotasks. Hosts provide them, and Node.js runs its timer, I/O, and setImmediate() callbacks from the phases of its own event loop.
Example
Say a dashboard schedules two zero-millisecond timers, one to load the inbox and one to load alerts, and the inbox callback updates a badge in a promise callback. The program shows where that update lands:
dashboard.mjs
setTimeout(() => {
console.log("Task 1: load inbox");
Promise.resolve().then(() => {
console.log("Microtask: update badge");
});
}, 0);
setTimeout(() => {
console.log("Task 2: load alerts");
}, 0);
console.log("Script done");
Running the file prints the badge update between the two timer callbacks:
$ node dashboard.mjs
Script done
Task 1: load inbox
Microtask: update badge
Task 2: load alerts
The top-level code runs to completion first, and each timer callback then runs as a separate macrotask. Both timers are due at the same moment, yet the microtask queued by the first callback runs before the second callback starts, because the event loop drains the microtask queue after every macrotask.
Step through dashboard.mjs to watch each macrotask leave the task queue and the badge update slip in before the next one:
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