JavaScript async function

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

An async function always returns a Promise. Inside it you can await other promises. Thrown errors become rejected promises.

JavaScript Syntax

JavaScript
async function load() {
  return "ready";
}
load().then((v) => console.log(v));
Try it Editor

How It Works

  1. async. Marks the function as asynchronous.
  2. return. Becomes a fulfilled promise.
  3. then. Reads the resolved value.

Examples

Example 1 — await inside

Pause for a promise.

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

How It Works

  1. await waits for fulfillment.
  2. Then logging continues.

Example 2 — Thrown errors reject

try/catch works with await.

JavaScript
async function boom() {
  throw new Error("fail");
}
bloom().catch((e) => console.log(e.message));
Try it Editor

How It Works

  1. throw inside async rejects the promise.
  2. catch handles it.

Example 3 — Async expression

const form.

JavaScript
const f = async () => 1;
f().then(console.log);
Try it Editor

How It Works

  1. Async arrow also returns a promise.

Frequently Asked Questions

Always. Even if you return a plain value, it is wrapped in a resolved promise.
In ES modules, yes. In classic scripts, use an async function or .then().

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