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

Returning Non-Promise Values

Confirm that returning primitives or objects from async functions wraps them as resolved Promises.

Returning Non-Promise Values

What you'll learn: You'll discover that returning any non-Promise value from an async function automatically wraps it in a resolved Promise.

The Automatic Wrapping Behavior

When you return a primitive (like a number, string, or boolean) or an object from an async function, JavaScript doesn't leave it as-is. Instead, it automatically wraps that value in a resolved Promise. This happens behind the scenes, ensuring that async functions always return Promises, regardless of what you explicitly return.

async function getName() {
  return "Alice";  // Returns a string, right?
}

const result = getName();
console.log(result);  // Promise { 'Alice' }

result.then(name => console.log(name));  // "Alice"

Even though you wrote return "Alice" (a simple string), the function actually returns Promise.resolve("Alice").

Why This Matters

This automatic wrapping is what makes async functions so convenient. You can write code that looks synchronous (just return a value), but the function signature remains consistent—it's always Promise-based. This means callers can always use .then(), .catch(), or await on the result.

async function getAge() {
  return 25;  // Primitive number
}

async function getUser() {
  return { name: "Bob", age: 30 };  // Plain object
}

// Both return Promises automatically
getAge().then(age => console.log(age));  // 25
getUser().then(user => console.log(user));  // { name: "Bob", age: 30 }

Key Takeaway: Any non-Promise value returned from an async function is automatically wrapped in Promise.resolve(), making async functions predictable and consistently Promise-based.