What Makes a Function Async
You'll learn how the async keyword fundamentally changes how a function behaves and what it returns.
The Async Transformation
When you place the async keyword before a function declaration, you're not just adding a label—you're transforming the function's entire behavior. An async function always returns a Promise, no matter what you write in its body.
Think of it like this: an async function is a "Promise factory." Even if you return a plain value like 42, JavaScript automatically wraps it in Promise.resolve(42). If you throw an error, it becomes Promise.reject(error). You can't escape this behavior—it's baked into what async means.
The Two Powers of Async
The async keyword grants your function two special abilities:
-
Automatic Promise wrapping: Whatever you return gets wrapped in a resolved Promise. Whatever you throw becomes a rejected Promise.
-
Await eligibility: Only inside an
asyncfunction can you use theawaitkeyword (which you'll learn about next).
Plain vs Async Function
// Regular function
function regularFunction() {
return 42;
}
// Async function
async function asyncFunction() {
return 42;
}
console.log(regularFunction()); // 42
console.log(asyncFunction()); // Promise { 42 }
asyncFunction().then(value => console.log(value)); // 42
Notice how the async version returns a Promise even though the body looks identical? That's the transformation at work.
Key Takeaway: The async keyword transforms any function into one that always returns a Promise and enables the use of await inside it—it's the gateway to modern asynchronous JavaScript syntax.