0Pricing
JavaScript Academy · Lesson

Microtasks and Promises

Learn why promise callbacks run first.

What Is a Microtask?

A microtask is a high-priority deferred job. Promise callbacks (.then, .catch, .finally) and queueMicrotask all schedule microtasks.

The key rule: after each synchronous run, all microtasks drain before any macrotask.

Promise Callbacks Are Deferred

Even an already-resolved Promise schedules its .then callback as a microtask. It does not run synchronously.

console.log('start');
Promise.resolve().then(() => console.log('promise then'));
console.log('end');

All lessons in this course

  1. The Call Stack
  2. Macrotasks and the Task Queue
  3. Microtasks and Promises
  4. queueMicrotask and Ordering
← Back to JavaScript Academy