13 / 17

Do all `async` functions return Promises? Why or why not?

Difficulty: 4/10
async functions, Promise return semantics, error propagation
  1. 1

    Yes, all async functions return Promises.

  2. 2

    The value returned by the async function is wrapped in a resolved Promise,

  3. 3

    and any error thrown inside the function is wrapped in a rejected Promise.

Scenario Questions

0-2 years experience

  1. 1Write a tiny async function that fetches data but doesn't use a return statement. When you call it without await, what do you get?
  2. 2If an async function throws an exception before any return, what does the caller see when they try to .then or await it?
  3. 3What will the console.log show for `console.log(typeof myAsync())` if `myAsync` is declared with the async keyword but returns nothing?

2-5 years experience

  1. 1We wrapped a callback‑based API in an async function, but some callers are getting undefined instead of a Promise, causing a crash. What could cause that behavior?
  2. 2During debugging you notice an async function sometimes returns a plain object, breaking a `.then` chain. Explain why that can happen and how to fix it.
  3. 3How would you refactor a utility that conditionally returns a value or a Promise so that it always returns a Promise when used with async/await?

5-8 years experience

  1. 1Our service has many async functions, and we’re seeing unhandled rejections because some of them return custom thenables. How would you audit the codebase and enforce a consistent Promise return contract?
  2. 2Design a TypeScript utility or ESLint rule that guarantees any function marked async has a return type of Promise<T>. What trade‑offs would you consider?
  3. 3When integrating a third‑party library that sometimes returns a thenable instead of a native Promise, how does that affect async functions and what strategy would you use to normalize the behavior?

8+ years experience

  1. 1We’re migrating a large legacy codebase that mixes callbacks, Promise chains, and async/await. At an architectural level, how would you ensure all async entry points expose a uniform Promise API and prevent future regressions?
  2. 2In a multi‑team microservices environment, some services expose async functions that return custom thenables. What long‑term maintenance risks does this pose, and how would you standardize the contract across teams?
  3. 3Describe a phased rollout plan to replace existing callback‑based interfaces with async functions while guaranteeing backward compatibility and consistent Promise semantics.

Follow-up Questions

  • Can you show a simple async function that returns a non‑Promise value and explain what the caller receives?
  • What happens to thrown errors inside an async function in terms of the returned Promise?
  • How does the JavaScript engine treat a thenable returned from an async function?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.