Async & promises · Output question
JavaScript async functions before and after await
An async function logs on both sides of await. Predict how its continuation fits around the caller’s synchronous work.
async function announce() {
console.log("inside");
await 0;
console.log("resumed");
}
announce();
console.log("outside");What gets logged?
Choose an output before opening the walkthrough, or check your answer in practice mode.
Reveal the answer and execution trace
inside
outside
resumedAn async function runs synchronously until await. Even awaiting a plain value resumes the function asynchronously.
- Line 6. Calling announce enters the function immediately.
- Line 2. The function logs "inside".
- Line 3. await suspends this function and schedules its continuation.
- Line 7. The outer script logs "outside" before the function resumes and logs "resumed".
Reference: Await control flow on MDN.