Skip to content

async

In JavaScript, async is a contextual keyword that marks a function as asynchronous, so the function always returns a promise and its body can pause at await expressions. The returned Promise fulfills with the function’s return value or rejects with any error the body throws.

The keyword works on function declarations and expressions, arrow functions, and object and class methods. Combined with function*, it creates an async generator, which can use both await and yield. The body runs synchronously until the first await, and then control returns to the caller.

Outside these positions, async isn’t reserved and stays a valid identifier. No line break is allowed between async and function, or JavaScript reads async as a variable name. Async functions were added in ES2017, and async generators in ES2018.

JavaScript async Keyword Syntax

The async keyword marks function declarations, arrow functions, and async generators:

Language: JavaScript Syntax
async function <name>([<parameters>]) {
  <statements>
}

const <binding> = async ([<parameters>]) => <expression>;

async function* <name>([<parameters>]) {
  <statements>
}

JavaScript async Keyword Examples

Marking a function async makes it return a promise, and async still works as a variable name:

Language: JavaScript
> async function getGreeting(name) {
…   return `Hello, ${name}!`;
… }
undefined

> getGreeting("Ada") instanceof Promise
true

> const async = "still a valid name";
undefined

The function returns a promise even though its body returns a plain string. The last line uses async as a variable name.

An async function runs synchronously up to its first await, so the caller’s next line prints before the function finishes:

Language: JavaScript Filename: load-user.mjs
async function loadUser(id) {
  console.log(`Loading user ${id}`);
  const user = await Promise.resolve({ id, name: "Ada" });
  console.log(`Loaded ${user.name}`);
  return user;
}

loadUser(1);
console.log("Called loadUser()");

Running the file shows that the caller’s line prints in the middle:

Language: Shell
$ node load-user.mjs
Loading user 1
Called loadUser()
Loaded Ada

JavaScript async Keyword Use Cases

  • Writing promise-based code as sequential steps with await
  • Handling asynchronous errors with try and catch
  • Defining async arrow functions for callbacks and event handlers
  • Producing values over time with async generators

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 5, 2026