← All notes

Async functions: writing promise code in a direct style

Answer: An async function lets you write promise-based code in a direct style. await waits for settlement without blocking the main thread.

How await works

web.dev describes async functions as a friendlier way to write promise-based code, almost as if the code were synchronous, without blocking the main thread.

Use the async keyword before a function definition, then use await within the function.

await pauses that function in a non-blocking way until the promise settles.

A fulfilled promise gives you the value. A rejection throws the rejected value.

Return values and rejections

Async functions always return a promise, whether you use await or not.

The returned promise fulfills with the function's return value, or rejects with a thrown value.

HTML still tracks unhandled promise rejections. A rejection that is not handled can remain in the outstanding rejected promises weak set.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Async functions: Making promises friendly; WHATWG, HTML Living Standard, Web application APIs. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://raw.githubusercontent.com/whatwg/html/main/LICENSE). Copyright WHATWG contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: web.dev, Async functions: Making promises friendly; WHATWG, HTML Living Standard, Web application APIs. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://raw.githubusercontent.com/whatwg/html/main/LICENSE). Copyright WHATWG contributors.

Cite this

Permanent ID: iil:note:bqk9ffak

iinventedlight. 2026. "Async functions: writing promise code in a direct style." iinventedlight Library, iil:note:bqk9ffak, version of 2026-11-23. https://iinventedlight.com/library/notes/javascript-async-await/. License: CC-BY-4.0.

@misc{iil_note_bqk9ffak,
  author = {{iinventedlight}},
  title = {{Async functions: writing promise code in a direct style}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/javascript-async-await/},
  note = {Permanent ID iil:note:bqk9ffak. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/javascript-async-await.md.