await
In JavaScript, the await keyword pauses an async function or a module until a promise settles, then evaluates to the promise’s fulfillment value or throws its rejection reason. It’s allowed inside functions marked with async and at the top level of a module.
The operand can be a Promise, a thenable, or any other value. Even for a value that isn’t a promise, the code after await resumes in a later microtask, so the caller keeps running in the meantime. A rejected promise throws at the await, where try and catch can handle it.
Top-level await was added in ES2022 and has been Baseline Newly available since 2026. Node.js supports it in ES modules since version 14.8. The same keyword starts the for await...of loop, added in ES2018, which waits for each value of an async iterable and is covered under for. The word await is reserved in modules and can’t name anything inside async functions or class static blocks, but other script code can still use it as an identifier.
JavaScript await Keyword Syntax
The await keyword works as an operator and in the for await...of loop:
await <expression>
for await (<declaration> of <asyncIterable>) <statement>
JavaScript await Keyword Examples
An await on a rejected promise throws inside the async function, where catch can handle it:
> async function readSetting(name) {
… try {
… return await Promise.reject(new Error(`No setting named ${name}`));
… } catch (error) {
… return `Fallback: ${error.message}`;
… }
… }
undefined
> await readSetting("theme")
'Fallback: No setting named theme'
The rejected promise throws at the await, and catch handles it. The last line uses top-level await, which works at the REPL prompt and in modules.
The for await...of loop waits for each promise in order, even when a later one settles first:
> const wait = (ms, value) =>
… new Promise((resolve) => setTimeout(resolve, ms, value));
undefined
> for await (const step of [wait(30, "fetch"), wait(10, "parse")]) {
… console.log(step);
… }
fetch
parse
undefined
JavaScript await Keyword Use Cases
- Reading the result of a promise-based API without
.then()chains - Catching rejected promises with
tryandcatch - Loading configuration or data at the top level of a module
- Consuming async iterables, such as streams, with
for await...of
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