JavaScript async/await

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

async/await is syntax over promises. Mark a function async, then await promises inside it. Use try/catch for rejections. Prefer this style for readable sequential async code.

JavaScript Syntax

JavaScript
async function main() {
  const a = await Promise.resolve(1);
  const b = await Promise.resolve(a + 1);
  console.log(b);
}
main();
Try it Editor

How It Works

  1. await. Waits for each promise.
  2. Sequential. Second await sees a+1.
  3. Log. Prints 2.

Examples

Example 1 — Parallel with Promise.all

Don't await in a slow chain when independent.

JavaScript
(async () => {
  const [a, b] = await Promise.all([
    Promise.resolve(1),
    Promise.resolve(2),
  ]);
  console.log(a + b);
})();
Try it Editor

How It Works

  1. Both start together.
  2. Await the combined promise.

Example 2 — try/catch

Handle rejections.

JavaScript
(async () => {
  try {
    await Promise.reject(new Error("nope"));
  } catch (e) {
    console.log(e.message);
  }
})();
Try it Editor

How It Works

  1. await throws on reject.
  2. catch handles it.

Example 3 — See async function

Declaration form.

JavaScript
async function f() { return 1; }
f().then(console.log);
Try it Editor

How It Works

  1. Returns a promise.

Frequently Asked Questions

It pauses only the async function—other tasks can still run on the event loop.
For sequential async logic, yes. For many independent calls, combine with Promise.all.

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