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

Await and Return Values

Returning an awaited promise is equivalent to returning the promise directly; both work, but style varies.

Await and Return Values

You'll learn: Whether to return await a promise or just return it directly, and why both approaches work.

The Core Idea

When you have an awaited promise in an async function, you can either return the awaited value or return the promise itself—both produce the same result for the caller. Here's the subtle difference:

// Option 1: await then return
async function getUser() {
  const user = await fetchUser();
  return user;
}

// Option 2: return the promise directly
async function getUser() {
  return fetchUser();
}

Both functions return a promise that resolves to the same value. Since async functions automatically wrap return values in promises, awaiting before returning doesn't change what the caller receives.

When Does It Matter?

Error handling context: If you return await, errors are caught within the current function's scope. If you just return the promise, errors bubble up directly to the caller.

Style preference: return await makes it explicit that you're waiting for an async operation. Direct return is more concise when you don't need to do anything with the value.

Inside try/catch: Use return await when you want errors caught by a local try/catch block:

async function safeGetUser() {
  try {
    return await fetchUser(); // Errors caught here
  } catch (error) {
    return null;
  }
}

Key Takeaway: Returning an awaited promise and returning the promise directly are functionally equivalent to the caller, but return await keeps error handling in the current function's scope—useful inside try/catch blocks.