Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

async await ordering

async functions return promises, and await pauses only the surrounding function. After the awaited promise settles, execution continues asynchronously through the microtask queue, so caller code and other microtasks can run first.

How it works

An async function starts running immediately, but await pauses that function and returns control to its caller. Once the awaited promise settles, the suspended continuation is scheduled as a microtask, so statements after await run after currently executing synchronous code and already queued microtasks.

Syntax

async function name(parameters) { await expression; }

Returns

An async function always returns a Promise; non-promise return values are wrapped automatically.

Key points

  • Every async function call produces a promise, even when the function returns an ordinary value.
  • await unwraps the fulfilled result and suspends the surrounding async function until settlement.
  • Promise.all is the documented composition pattern for awaiting several promises together.

Example: Execution resumes after await

async function demo() {
  console.log("A");
  await Promise.resolve();
  console.log("C");
}

demo();
console.log("B");
// A, B, C

The function runs synchronously through the await, then resumes asynchronously; the caller's next synchronous statement runs first.

When to use it

Dependent async steps

Read sequential asynchronous results where each step depends on the previous one.

Readable error handling

Handle promise failures with ordinary try/catch control flow.

Concurrent promise coordination

Coordinate several independent operations with Promise.all.

Interview questions

QWhy does code after await run later?

An async function begins synchronously until it reaches await. At that point it yields to its caller, and the code after await resumes in a microtask after the awaited value settles.

Follow-up: What happens with an already-resolved promise? The continuation is still deferred, and other already-scheduled microtasks are processed first.

QDoes await block the whole program?

await pauses the surrounding async function rather than blocking JavaScript globally. Caller code and other independent asynchronous work can continue while the promise is pending.

Follow-up: How can two operations start concurrently? Create both promises before awaiting them, then await Promise.all on the group.

QWhat does async change about a function's return value?

async guarantees that the function returns a promise; ordinary returned values are automatically wrapped as fulfilled promises. A rejection from the awaited promise propagates as an exception unless handled.

Follow-up: How should multiple independent promises be coordinated? Use Promise.all when all results are required, rather than awaiting them one by one.

  • Promise
  • Promise.all
  • then
  • catch
  • finally
  • microtasks

Source: Async/await. Checked 2026-10-15.