When does the rest of an async function after await run in JavaScript?
As a microtask, when the awaited promise settles. The event loop runs microtasks after the current synchronous code completes and before the next macrotask. This is why async functions do not block.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How async/await Works Behind the Scenes in JavaScript
async functions return promises. await pauses the function and yields control to the caller. The rest of the function runs as a microtask when the awaited promise settles. await unwraps the promise or throws the rejection reason.
No. await pauses the async function and yields control to the caller. The caller continues running synchronous code. The rest of the async function runs as a microtask when the awaited promise settles.
Code before await runs synchronously. await pauses and schedules the rest as a microtask. Code after the foo() call runs next (sync). Then the rest of foo runs (microtask). So: 1, 3, 2.
Still have questions?
Browse all our FAQs or reach out to our support team
