# JavaScript async/await under the hood

> async functions always return promises; await pauses the function until that promise settles.

Source: https://fullbytedeveloper.com/blog/javascript-async-await-under-the-hood
Published here: 2026-12-03, updated 2026-12-03

`async`/`await` is syntax for promises, not a second runtime [1] [2]. An `async` function always returns a `Promise`; `await` suspends that function until the awaited promise fulfills or rejects [1]. Read this after [JavaScript promises and the event loop](/blog/javascript-promises-event-loop-quick-start). Parallelism language: [concurrency vs parallelism](/blog/concurrency-vs-parallelism-plain).

## Quick start (under a minute)

```bash
node -e "async function f(){return 1;} console.log(f() instanceof Promise); f().then(v=>console.log(v));"
```

You should see `true` then `1`: the async function handed the caller a Promise, not the raw number.

## Worked example on this draft host

MDN states that async functions always return promises and that `await` pauses the async function body [1]. The snippet below contrasts sequential awaits with `Promise.all` on two independent delays.

Observed on this draft host (Node.js v22.23.5, Linux, 2026-12-03):

```text
foo() instanceof Promise true
foo().then value 1
parallel A B ms 50
sequential A B ms 101
```

The sequential path waited about twice the single delay because each `await` finished before the next timer started. The parallel path started both timers first, so total wall time stayed near one delay. Your millisecond numbers will jitter; the ratio is what matters for teaching.

Program used:

```js title="async_timing_demo.js"
async function slow(ms, label) {
  await new Promise((r) => setTimeout(r, ms));
  return label;
}
async function foo() {
  return 1;
}
console.log("foo() instanceof Promise", foo() instanceof Promise);
foo().then((v) => console.log("foo().then value", v));

(async () => {
  const t0 = Date.now();
  const a = await slow(50, "A");
  const b = await slow(50, "B");
  console.log("sequential", a, b, "ms", Date.now() - t0);
})();

(async () => {
  const t0 = Date.now();
  const pa = slow(50, "A");
  const pb = slow(50, "B");
  const [a, b] = await Promise.all([pa, pb]);
  console.log("parallel", a, b, "ms", Date.now() - t0);
})();
```

Run with `node async_timing_demo.js` after saving the file.

## See control flow as promise chaining

<figure aria-label="async function pausing at await on call stack while microtasks resume after promise settles">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 240" role="img" aria-hidden="true">
  <rect x="0" y="0" width="360" height="240" rx="12" fill="#0b1f3a"/>
  <text x="90" y="22" text-anchor="middle" font-size="12" font-weight="600" fill="#e6edf7" font-family="system-ui,sans-serif">call stack</text>
  <text x="270" y="22" text-anchor="middle" font-size="12" font-weight="600" fill="#e6edf7" font-family="system-ui,sans-serif">event loop queues</text>
  <line x1="180" y1="28" x2="180" y2="224" stroke="#14b8a6" stroke-width="0.642857" stroke-dasharray="4 4"/>
  <rect x="38.5714" y="36" width="102.857" height="40" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="90" y="60" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">sync prelude</text>
  <rect x="38.5714" y="74" width="102.857" height="40" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.28571"/>
  <text x="90" y="98" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">await fetch (paused) [1]</text>
  <rect x="38.5714" y="112" width="102.857" height="40" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286" stroke-dasharray="3 3"/>
  <text x="90" y="136" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">resume after settle</text>
  <rect x="205.714" y="39.5" width="128.571" height="45" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="270" y="66" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">macrotask: setTimeout I/O</text>
  <rect x="205.714" y="87.5" width="128.571" height="45" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="270" y="114" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">microtask: promise jobs [2]</text>
  <path d="M220 94 L280 94 L280 110 L320 110" fill="none" stroke="#14b8a6" stroke-width="0.771429"/>
  <text x="90" y="168" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">caller gets Promise immediately</text>
  <text x="270" y="168" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">other tasks run while awaiting</text>
  <text x="180" y="214" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">sequential awaits add wall time; Promise.all overlaps independent work</text>
</svg>
</figure>

MDN: code before the first `await` runs synchronously; after each `await`, the remainder behaves like code inside a `.then` callback [1] [2]. That picture is why a missing `await` on an inner async call returns a pending Promise instead of the value you expected.

## Implicit Promise wrapper

MDN documents that returning a non-promise value from an async function wraps it as if with `Promise.resolve` [1]:

```js
async function foo() {
  return 1;
}

function fooPromise() {
  return Promise.resolve(1);
}
```

Callers of `foo()` must treat the result as asynchronous even when the body looks synchronous. Logging properties on the return value without awaiting is a common beginner bug [2].

## Walk a fetch with await

MDN Learn rewrites promise chains with `try`/`catch` around awaits [2]:

```js
async function fetchProducts() {
  try {
    const response = await fetch(
      "https://mdn.github.io/learning-area/javascript/apis/fetching-data/can-store/products.json",
    );
    if (!response.ok) {
      throw new Error(`HTTP error: ${response.status}`);
    }
    const data = await response.json();
    console.log(data[0].name);
  } catch (error) {
    console.error(`Could not get products: ${error}`);
  }
}

fetchProducts();
```

That block matches MDN Learn's async/await rewrite of the products fetch (accessed 2026-12-03), including try/catch around awaits [2].

## Prefer Promise.all when work is independent

If you `await` task A completely before starting task B, B cannot overlap A even when they do not depend on each other [1]. Start both promises, store the returned promises in variables, then `await Promise.all([...])` when you only need both results together [1] [2].

Sequential awaits remain correct when each step needs the previous result: authenticate, then fetch a user-specific URL, then parse JSON. The timing demo above is the minimal proof for independent delays.

## Keep errors visible

A rejected promise at an `await` throws inside the async function [1]. Wrap risky awaits in `try`/`catch`, or attach `.catch` on the promise returned by the async function, so failures become visible instead of unhandled rejections [2].

```js
async function mayFail() {
  try {
    return await Promise.reject(new Error("nope"));
  } catch (err) {
    return "recovered";
  }
}
```

Bare `await` outside an async function or ES module top level is a syntax error [1]. Top-level await in modules changes load order; treat that as a separate module-system topic from this page.

## Trace microtasks with a tiny script

Promises settled by `await` schedule microtasks. Pair with [JavaScript promises and the event loop](/blog/javascript-promises-event-loop-quick-start) when you need queue order drawn step by step.

```js title="microtask_order.js"
async function loadName() {
  const response = await fetch(
    "https://mdn.github.io/learning-area/javascript/apis/fetching-data/can-store/products.json",
  );
  const data = await response.json();
  return data[0].name;
}

console.log("sync start");
loadName()
  .then((name) => console.log("then name", name))
  .catch((e) => console.error(e));
console.log("sync end");
```

You should see `sync start`, then `sync end`, then `then name` with the fetched string when the request succeeds [2]. The middle lines prove the async function returned a pending Promise immediately.

## Relation to the event loop posts

Promises schedule microtasks. `await` is how you write microtask-heavy code without chaining `.then` manually [1] [2]. It does not move CPU work to another thread. Heavy computation still blocks the loop unless you offload to workers or native addons. Pair this page with [JavaScript promises and the event loop](/blog/javascript-promises-event-loop-quick-start) for queue order and with [concurrency vs parallelism](/blog/concurrency-vs-parallelism-plain) when someone says "async is parallel."

## Top-level await in modules

ES modules may use `await` at the top level when the bundler or runtime supports module async evaluation [1]. That changes load order: importers wait for the module graph to settle before running. It is useful for config loaders, not a replacement for lazy initialization in libraries consumed by both Node and browsers.

Library authors sometimes expose both sync and async APIs for the same resource. Document which path returns a Promise so callers do not double-await. TypeScript's `Promise<T>` return type helps static checks catch those mistakes before runtime.

`Promise.allSettled` waits for every promise without failing fast when one rejects [2]. That pattern fits bulk health checks. `Promise.race` returns the first settled result, useful for timeouts implemented as competing promises.

## What suspension actually saves

When an async function hits `await`, the runtime stores the remaining bytecode or generator-like state for that function and returns a Promise to the caller [1]. Locals stay on that suspended activation; they are not copied into a worker thread. That is why a tight `for` loop of pure math after `await` still blocks painting: the continuation runs on the same event-loop turn once the Promise resolves [1] [2].

Cancellation is not built into bare `await`. You pass an `AbortSignal` into `fetch`, or you race a timeout Promise, or you check a flag after each await. Without that, a navigated-away page can still finish network work and touch dead DOM unless you guard the continuation.

Debugging tip: in Chromium DevTools, async stack traces stitch the await sites together so a rejection shows the caller that started the chain, not only the microtask that threw [2]. Enable async stacks when a `.then` chain looks like it came from nowhere.

## Failure modes worth naming

Writing `async` on every function "for performance." Async adds promise wrapping overhead. Use it when the function actually awaits asynchronous work.

Forgetting `await` on an inner async call and getting a Promise where you wanted a value.

Awaiting independent network calls in series and blaming the API for latency.

`async`/`await` catches errors automatically. You still need `try`/`catch` or `.catch`.

Treating returned promises like plain objects (`result.foo` without await).

`await` freezes the entire runtime. It only suspends the current async function until its promise settles [1].

Rewrite one sequential fetch chain with `Promise.all` on two URLs that do not depend on each other, log `Date.now()` deltas, and keep the slower style only where step two truly needs step one's JSON. That one measurement ends more debates than another slide on microtasks.

Send this to the friend who thinks await moves work onto another CPU core.

Image: Stacked dark blocks with one orange edged slot feeding a solid arrow into a segmented ring that drops teal and orange cylinder rows, no people and no readable text.
https://fullbytedeveloper.com/media/javascript-async-await-under-the-hood/javascript-async-await-under-the-hood-venice.webp
await pauses one async function, not the whole runtime.

## Sources

1. [MDN: async function, accessed 2026-12-03](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
2. [MDN Learn: How to use promises (async and await section), accessed 2026-12-03](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Async_JS/Promises)
3. [Full Byte Developer: JavaScript promises and the event loop](https://fullbytedeveloper.com/blog/javascript-promises-event-loop-quick-start)
4. [Full Byte Developer: Concurrency vs parallelism](https://fullbytedeveloper.com/blog/concurrency-vs-parallelism-plain)
