async
In one line
The async keyword declares a function that always returns a promise, enabling await inside it.
In simple words
The async keyword marks a function as asynchronous. An async function always returns a promise — if you return a plain value, JavaScript wraps it in a resolved promise automatically. The real power of async is that it lets you use await inside the function body.
Before async/await, asynchronous code used nested callbacks or promise chains. With async, you can write async code that reads top-to-bottom like synchronous code, while still being non-blocking. The event loop keeps running while your function waits.
Marking a function async does not make it run on a separate thread — JavaScript is single-threaded. It only changes how the function's return value is wrapped and enables await. The actual concurrency comes from the underlying APIs (fetch, timers, etc.).
Example
async function getUser(id) {
const response = await fetch(`/api/users/${id}`);
const user = await response.json();
return user;
}
getUser(42).then((user) => console.log(user));async lets you use await inside. The function returns a promise that resolves with the user.
Common confusions
Confused with: await
The difference:
asyncdeclares a function that returns a promise;awaitpauses execution inside an async function until a promise settles. You use them together: async enables await.
Related terms
Related Resources
Related Lessons
- Async JavaScript
async/await in depth
Learn the fundamentals
Deepen your understanding with structured lessons on this topic.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.