microtask

A small job, such as a promise callback, that runs as soon as the current piece of JavaScript finishes, before the event loop handles anything else.

In more detail

The whole microtask queue is emptied each time the call stack becomes empty, so microtasks that keep queuing more can block everything else. Promise callbacks and queueMicrotask() create microtasks.

Examples

In the browser: The event loop drains the whole microtask queue after every task, including microtasks added while draining. That makes microtasks fast but risky: a chain that keeps adding more starves everything else, including rendering in a browser.
In Node.js, process.nextTick() callbacks run even before promise microtasks.
The course exercise uses them to simulate interleaving urgent and background work.

Related terms

Taught in

References