Facebook Pixel

What is the output of async function with await and console.log?

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.

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.

Yes. async functions return promises. await unwraps promises. try/catch with await is equivalent to .catch with .then. You can mix await with Promise.all.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.