← Back to topic library
Dev MaxxingBeginnerJavaScript75 sec
async/await
async/await is syntax that lets code wait for a Promise to settle using a sequential, top-to-bottom style, instead of chaining '.then()' calls.
Prerequisite: Promise
What matters
It makes asynchronous code easier to read and reason about, since it looks like ordinary step-by-step code while still not blocking the rest of the program while waiting.
Example
Writing 'const data = await fetchData();' pauses that function at that line until the Promise resolves, then continues with the result.
Common misconception
'await' does not block the entire program while waiting; it only pauses the specific async function it's used in, letting other code keep running.
Recall question
What does 'await' pause, and what does it not block?
Keywords and related concepts
async/awaitasynchronouspromisesyntax sugar