Skip to content

OutputNot attempted

Where does an async function pause?

async function a() {
console.log(1);
await b();
console.log(2);
}
async function b() {
console.log(3);
}
console.log(4);
a();
console.log(5);

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

An async function runs synchronously until its first await. b() logs 3 synchronously; the code after await resumes as a microtask, after the sync log 5.