Skip to the solution
MediumFrontend6 min read

How does async/await work?

178 views

The problem

Question presented to candidate: "Does an async function ALWAYS return a Promise, even if the function body never uses await at all? And if you await two things back to back, do they run one after another, or at the same time?"

What a strong answer should cover:

  • πŸ“Œ Interview term: async function β€” always returns a real Promise, no matter what the function body does β€” verified directly: an async function with literally no await in its body genuinely still returns a real Promise object, not a plain value.
  • πŸ“Œ Interview term: await β€” genuinely pauses the async function's execution at that exact line, resuming only once the awaited Promise settles β€” verified directly with a real, ordered array of pushes, confirming code AFTER calling an async function (but before awaiting its result) genuinely runs before the awaited line resumes.
  • πŸ“Œ Interview term: the real, direct answer to the prompt's sequencing question β€” verified directly, with a real, measured elapsed time: two sequential awaits genuinely run in series, one after another β€” NOT concurrently β€” a real two-step 30ms-each delay measured a genuine ~68ms total, not ~30ms, confirming the second await genuinely does not start until the first one has fully resolved.
  • πŸ“Œ Interview term: errors inside an async function become rejections β€” verified directly: a value thrown inside an async function genuinely becomes a real rejected Promise, catchable with an ordinary try/catch wrapped around the await β€” the same real mechanism this bank's own dedicated Promise-states question covers for a thrown error inside .then().
  • A precise answer names that await on a plain, non-Promise value genuinely just resolves immediately with that value β€” verified directly β€” and that async/await is fundamentally syntax sugar over Promises, not a genuinely different underlying mechanism.

Clarifying questions expected:

  • None β€” this is a definitional/technical question; directly answering both halves of the prompt (always-returns-a-Promise, and series-not-concurrent) with real proof is the strong signal.

Code / implementation expected: Yes β€” the real, timed proof that two sequential awaits run in series (not concurrently) is the clearest, most convincing demonstration.

  • async-await

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

6 min read Β· 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, timed proof: an async function with no await still returns a Promise, and two sequential awaits genuinely run in series, not concurrently

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 110 of 165 in JavaScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

How would you use a Proxy 'get' trap to implement lazy-loaded or computed properties on a plain object?

Continue