How async/await Really Works in JavaScript: Beyond the Surface Model
Many developers treat async/await as syntax that simply makes asynchronous code read top-to-bottom, but this mental model breaks down when debugging complex execution orders. Every async function automatically wraps its return value in a Promise, meaning it always returns a Promise regardless of what is explicitly written. When execution hits an await expression, the function suspends and hands control back to the event loop — it does not block the JavaScript thread. The continuation after await is queued as a microtask, which only runs once the current call stack is fully empty. This is why, in a sequence like console.log('C'), test(), console.log('D'), the output is C, A, D, B — even when the awaited Promise is already resolved.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in