JavaScript await

Beginner
6 min read
Updated: Nov 2026
3 examples

Definition and Usage

await pauses an async function until a Promise settles, then returns the resolved value (or throws if the Promise rejects).

JavaScript Syntax

JavaScript
async function loadName() {
  const value = await Promise.resolve("Ada");
  console.log(value);
}
loadName();
Try it Editor

How It Works

  1. async required. You can only use await inside an async function (or at the top level of an ES module).
  2. Wait for settle. await yields until the Promise fulfills or rejects.
  3. Use the value. The expression evaluates to the fulfilled value—here "Ada".

Examples

Example 1 — Await a Resolved Promise

Read a value from a fulfilled Promise.

JavaScript
async function run() {
  const n = await Promise.resolve(42);
  console.log(n);
}
run();
Try it Editor

How It Works

  1. Pause. Execution waits until the Promise fulfills.
  2. Continue. Then n is 42 and logging runs.

Example 2 — Catch a Rejection

Wrap await in try...catch when a Promise may reject.

JavaScript
async function run() {
  try {
    await Promise.reject(new Error("boom"));
  } catch (err) {
    console.log("Caught: " + err.message);
  }
}
run();
Try it Editor

How It Works

  1. Reject throws. A rejected Promise makes await throw.
  2. catch handles it. The catch block prints the message.

Example 3 — Await in Sequence

Run async steps one after another.

JavaScript
async function run() {
  const a = await Promise.resolve(2);
  const b = await Promise.resolve(a * 3);
  console.log(b);
}
run();
Try it Editor

How It Works

  1. First await. Gets 2.
  2. Second await. Multiplies by 3 and logs 6.

Frequently Asked Questions

It waits for a Promise inside an async function and returns the resolved value.

Only at the top level of ES modules. In classic scripts you need an async function.

Use try...catch around the await expression.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful