QamoosTech
Programming FundamentalsRuntime and memoryIntermediateJavaScript

Microtask Queue

PronunciationMY-kroh-task KYOO

Definition

The microtask queue holds small jobs, mainly Promise callbacks (then, and the code after an await), that the event loop runs right after the current task and before any timer or other task.

Where you hear it

In JavaScript execution-order puzzles, "promise vs setTimeout" interview questions and subtle async bugs.

Examples

  • The promise callback prints before the setTimeout one because microtasks run first.
  • An endless chain of microtasks can starve rendering.
  • The then callback runs before the timer, because promise callbacks are microtasks.

Common mistake

Assuming all callbacks share one queue. Promises and timers use different queues with different priorities.

Don't confuse with

The macrotask (task) queue, which holds timers, I/O and user events and is processed one task per loop turn.

Say it at work

  • In a meeting or chatMicrotasks drain completely before the next task.
  • In an email or ticketWhat's the output order here?