Async/Await
ELI5 — The Vibe Check
Async/await is syntactic sugar that makes Promises look like normal, readable code. Instead of chaining .then().then().catch(), you write code that looks synchronous but actually waits for async operations. It's the reason modern JavaScript code is readable by humans.
Real Talk
Async/await is a JavaScript syntax (introduced in ES2017) that allows writing asynchronous code in a synchronous style. The async keyword marks a function as asynchronous (it implicitly returns a Promise). The await keyword pauses execution inside the async function until the awaited Promise resolves. Error handling uses standard try/catch.
Show Me The Code
// Without async/await (Promise chains)
function loadUser(id) {
return fetch(`/api/users/${id}`)
.then(res => res.json())
.then(user => user.name)
.catch(err => 'Unknown')
}
// With async/await (much cleaner)
async function loadUser(id) {
try {
const res = await fetch(`/api/users/${id}`)
const user = await res.json()
return user.name
} catch {
return 'Unknown'
}
}
When You'll Hear This
Async functions always return a Promise, even if you return a plain value.,Don't await in a loop — use Promise.all for parallel requests.,Forgetting await is a top-tier bug source.
Related Terms
Callback
A callback is just a function you pass to another function, saying 'when you're done, call this.
Event Loop
JavaScript can only do one thing at a time (single-threaded), but the Event Loop is the trick that makes it seem like it can multitask.
Fetch
Fetch is the modern, built-in JavaScript way to make HTTP requests to APIs. You tell it a URL, it goes and gets the data, and you handle the response.
Promise
A Promise is JavaScript's way of saying 'I'll give you a value eventually — it's not ready yet, but I promise.