Course contentsShow
← JavaScript
Lesson 1201 of 2,72327. The Event LoopFree lesson

Async/Await Under the Hood

Understand that await schedules microtasks just like .then does internally.

Async/Await Under the Hood

You'll learn: How async/await secretly uses the same microtask scheduling as .then() callbacks.

The Syntactic Sugar Revealed

When you write await, JavaScript doesn't magically pause your code in a fundamentally different way than promises. Under the hood, await is syntactic sugar that the engine translates into promise .then() callbacks. This means every await schedules a microtask, just like chaining .then() does.

Think of it like this: await is a friendly assistant who takes your code and rewrites it into promise chains behind the scenes before running it.

How It Actually Works

When the JavaScript engine encounters await somePromise, it:

  1. Pauses the async function's execution
  2. Unwraps the promise (equivalent to calling .then())
  3. Schedules the continuation as a microtask
  4. Returns control to the call stack

The code after await becomes the callback inside a .then(). This is why async functions don't block the main thread—they yield control and rejoin execution via the microtask queue, exactly like promise chains.

Why This Matters

Understanding this connection helps you predict execution order. When you see:

async function example() {
  await fetchData();
  console.log('After await');
}

The engine treats it similarly to:

fetchData().then(() => {
  console.log('After await');
});

Both schedule microtasks. Both allow other code to run first. Both follow the same event loop rules.

Key Takeaway: await is promise .then() in disguise—it schedules microtasks identically, which is why async/await and promise chains have the same execution timing behavior.