Skip to the workspace
Pebellslearn by building
Asynchronous JavaScript  ›  Lesson

async/await

async/await 12 min

javascript / async/await

Explore each scene at your own pace.

01 · async/await

async/await

async/await

An async function always returns a promise. await pauses that function’s continuation until its operand settles; rejection behaves like a throw at the await point.

Wait for the value where you need it without blocking the whole thread.

See the mechanism

Walk through the modelasync/awaitAuthored snapshots of the example; use Run below to test the code.
Statecaller receives a promise
Async return values are wrapped in a promise.
1 of 3

Follow one example

javascript

The awaited fulfillment supplies article, then the function returns the title through its own promise. This editor wraps code in an async function, so the shown outer await works here; in a real file, top-level await needs a supported module context. Independent requests need not be awaited one by one: Promise.all can combine them, but handle its rejection behavior deliberately.

Predict, change and check

Predict: Will an async function return a plain title immediately if you omit await at its call site?

Test your explanation: Print typeof articleTitle().then to recognize the promise interface. Then reject the fixture and add try/catch around await to produce a deliberate error result.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Await follows an outcome without freezing the host

An async function returns a promise. await pauses that async function's continuation while allowing the host to do other work; it does not block the whole browser like a busy loop. Even an already fulfilled promise resumes through asynchronous continuation semantics.

A try/catch can handle a rejection that is awaited within its protected region. Returning a promise without awaiting it can change which local catch or finally observes the operation. Start independent operations deliberately; several sequential awaits can serialize work that does not actually depend on earlier results.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.