Learn JavaScript

Lesson 5 of 9 · Async 2: Promises, async/await and fetch

Module 13 · Async 2: Promises, async/await and fetch

Under the Hood: Microtasks, the Turns an await Costs, Thenables and Unhandled Rejections

ProReading

Module 12 drew the event loop with two queues. The task queue holds timers and I/O, and the microtask queue was named but left for later. This lesson finishes that picture, because promises live in the second queue. Once you see it, the print-order puzzles of interviews stop being puzzles.

Checking what this lesson needs for you…

What is inside Under the Hood: Microtasks, the Turns an await Costs, Thenables and Unhandled Rejections

  1. Microtasks, finished
  2. How many turns an await costs
  3. A returned promise costs two more turns
  4. Thenables: anything with a then
  5. What an async function returns when it throws
  6. Unhandled rejections in Node 22