OP1 week ago
Async/await confused me at first because most explanations skipped the problem it solves.
JavaScript runs code line by line, but things like API calls, file reads, and database queries take time. If JavaScript waited for each one, your page would freeze. Instead, it starts the slow task, continues running other code, and handles the result when it is ready.
A Promise represents that future result: it either resolves with data or rejects with an error.
Before async/await, we used .then() chains:
js
fetchData().then(result => process(result)).catch(error => console.log(error))
Async/await does the same thing but reads more like normal code:
js
async function load() {
try {
const result = await fetchData()
process(result)
} catch (error) {
console.log(error)
}
}
await pauses only that function, not the whole page. The common beginner mistake is forgetting await, then accidentally using a Promise instead of actual data. Try rewriting one .then() chain into async/await—it clicks quickly.
⚡
Login to join the discussion.