Course contentsShow
← JavaScript
Lesson 1332 of 2,72330. Async/AwaitFree lesson

Automatic Promise Wrapping

Understand how return values in async functions are automatically wrapped in resolved Promises.

Automatic Promise Wrapping

You'll learn how async functions automatically turn your return values into resolved Promises—no manual wrapping required.

The Magic Behind Async Functions

When you mark a function with the async keyword, JavaScript gives you a powerful guarantee: whatever you return gets automatically wrapped in a Promise. Even if you return a plain value like a number or string, the function will always return a Promise that resolves to that value.

Think of an async function like a gift-wrapping service. No matter what you hand over—a book, a toy, or even something already wrapped—it always comes back in their standard wrapping paper. You can't return an "unwrapped" value from an async function.

How It Works

async function getNumber() {
  return 42;
}

const result = getNumber();
console.log(result); // Promise { <fulfilled>: 42 }

result.then(value => {
  console.log(value); // 42
});

Even though we wrote return 42 (a plain number), the async function automatically wrapped it in Promise.resolve(42). The caller always receives a Promise.

Returning Promises from Async Functions

What if you explicitly return a Promise? JavaScript is smart about this—it doesn't double-wrap:

async function getData() {
  return Promise.resolve('hello');
}

// Still returns Promise { <fulfilled>: 'hello' }
// Not Promise { <fulfilled>: Promise { ... } }

The async function recognizes you're already returning a Promise and doesn't add another layer.

Key Takeaway: Async functions automatically wrap all return values in resolved Promises, ensuring consistent Promise-based interfaces regardless of whether you return plain values or Promises themselves.