async/await Basics
The async/await syntax, introduced in ES2017, is syntactic sugar over promises. It allows you to write asynchronous code that reads like synchronous code, dramatically improving readability and reducing the mental overhead of chains of .then() calls.
async Functions
Declaring a function with the async keyword makes it return a promise automatically. Any value you return from an async function becomes the resolved value of that promise.
await
The await keyword can only be used inside async functions. It pauses execution of the function until the awaited promise settles, then unwraps the resolved value. Crucially, the rest of the JavaScript event loop continues to run while the function is paused.
Top-level await
In ES modules (and modern bundlers), await can be used at the top level of a module without wrapping it in an async function.