Question

Why does my async function return a Promise instead of a value?

Vault Verified
Curated Intelligence
Definitive Source
Answer

This is the defining behaviour of async functions rather than a mistake. Declaring a function async wraps its return value in a promise automatically. Returning a number from an async function produces a promise that resolves to that number, and there is no way to make it return the number directly, because the point of the construct is that the result may not exist yet.

To get the value you have to wait for it, which means either awaiting the call inside another async function or attaching a handler to the promise. Forgetting this produces a recognisable symptom: logging the result shows a pending promise rather than the data, and passing it onward causes downstream code to fail on a value that is not the shape it expected.

A few specific traps recur.

  • Calling an async function without awaiting it, usually because the calling function was not itself marked async. The call still runs, but execution continues immediately and the result is never collected.
  • Using an async callback inside an array method that does not understand promises. Mapping with an async callback produces an array of promises rather than an array of values. Waiting on all of them together converts it back.
  • Awaiting inside a loop when the operations are independent. This is correct but runs them one after another, which can be dramatically slower than starting them together and waiting once at the end.

There is also a correctness hazard worth knowing. An unawaited promise that rejects becomes an unhandled rejection, which in modern runtimes can terminate the process. Awaiting is therefore not only about collecting the value, it is also about ensuring failures are attached to something able to handle them.

Related Questions