Waiting for async function to return true or false - how do I check return value?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In JavaScript, an async function does not return a plain boolean immediately. It returns a Promise<boolean>, which means you must wait for the promise to resolve before you can tell whether the answer is true or false.
Why a Direct if Check Fails
This is the source of most confusion:
result is a promise object, not the final boolean. That is why this pattern is wrong:
The if statement runs immediately and tests the promise object itself instead of the value that will arrive later.
Use await Inside Another Async Function
The cleanest solution is to call the async function from another async function and use await.
await pauses only the surrounding async function. It does not block the entire JavaScript runtime, which is why this style fits naturally into event-driven code.
Use .then When the Caller Is Not Async
If you are in code that is not marked async, or you prefer promise chaining, use .then.
This does the same work as await, just in callback form.
false Is Not the Same as an Error
An async function can resolve to false, or it can reject with an error. Those outcomes should not be treated as identical.
A resolved false means the answer is no. A rejection means the check could not complete. Mixing those up can hide outages and backend bugs.
Running Several Checks Together
If you need several boolean results and the checks are independent, run them concurrently instead of awaiting one after another.
This is both faster and clearer when order does not matter.
TypeScript Makes the Intent Clearer
If you are using TypeScript, declare the return type explicitly. That makes misuse harder because the caller sees immediately that a promise is involved.
Good naming also helps even in plain JavaScript. A function named fetchPermission is less likely to be mistaken for a synchronous boolean helper than one named isReadyNow.
Top-Level await and UI Event Handlers
In modern module-based environments, top-level await may be available. In browsers and UI frameworks, it is still more common to keep the async logic inside handlers or helper functions.
For example, inside a click handler you can call an async function and await the boolean before deciding what UI to show. The core idea stays the same: the value arrives later, so the code that depends on it must be asynchronous too.
Common Pitfalls
The most common mistake is branching on the promise object itself instead of awaiting the resolved value.
Another issue is forgetting to handle rejection. A network failure should not silently look like an ordinary false unless that fallback is intentional.
Developers also sometimes try to force JavaScript into synchronous waiting. In normal application code, the better pattern is to keep the control flow async and explicit.
Finally, do not serialize independent checks with repeated awaits unless the order actually matters.
Summary
- An
asyncfunction returns a promise, not a raw boolean. - Use
awaitor.thento access the resolved value. - Treat rejection separately from a business-logic
falseresult. - Use
Promise.allfor independent async checks. - Clear naming and explicit types make async return values easier to use correctly.

