All topics
Asyncintermediate

Async/Await Syntax

Syntactic sugar over Promises that lets asynchronous code read like synchronous code, using async functions and the await keyword.

async/await, introduced in ES2017, is built entirely on top of Promises and provides a syntax that lets asynchronous code be written and read almost exactly like synchronous code, without changing the underlying non-blocking execution model. Because it's the dominant style for writing async JS today, interviewers expect fluency here.

async/await is like reading a recipe with 'wait for the water to boil' written as one instruction, instead of manually describing checking the pot every few seconds.

Key Concepts

1
Marking a function async guarantees it always returns a Promise. Inside an async function, await can be placed before any promise, pausing execution of that function until the awaited promise settles, then returning its resolved value or throwing its rejection reason.
2
Because await throws on rejection, error handling uses ordinary try/catch blocks instead of .catch() chains. await doesn't block the JS thread; it suspends the current async function, letting other code run, and resumes once the awaited value is ready.
3
A common performance pitfall is awaiting independent operations sequentially when they could run concurrently via Promise.all.