Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

async — asynchronous functions

async marks an asynchronous function: calling it returns a Promise, and its body can use await. It does not automatically run code in parallel or on a separate thread.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

async function name(parameters) { /* body */ }
const name = async (parameters) => { /* body */ };

async marks an ordinary asynchronous function, method, or arrow function; this syntax is part of ECMAScript 2017. It is a keyword but not a reserved word: it can also be a variable name. A line terminator is forbidden between async and function; a corresponding restriction applies between async and an arrow function's parameters.

Calling an ordinary async function always returns a new Promise. return determines its result; a returned promise is adopted rather than becoming a nested result. Omitting return produces undefined, and an uncaught exception rejects the promise. Handle the result using await or .then(), and errors using try...catch around await or .catch().

The body runs synchronously until the first await. await suspends that function, not the whole program; resumption happens later, even for an already fulfilled promise. async alone does not move computation to a separate thread: a long loop still blocks the current thread.

The example demonstrates the order start, outside, 42. An async function* is a separate case: it returns an asynchronous generator rather than a Promise directly. This entry concerns language syntax, not Web API availability; the repository's Node.js version does not establish browser API support.

Examples

async function double(value) {
  console.log("start");
  const result = await Promise.resolve(value * 2);
  return result;
}

const pending = double(21);
console.log("outside");
pending.then((value) => console.log(value));

Result

start
outside
42

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources