What is the output of async function with await and console.log in JavaScript?
Code before await runs synchronously. await pauses the function 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 for the example above.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Event Loop Interview Questions in JavaScript
1, 4, 3, 2. Sync code runs first (1, 4). Then all microtasks (3). Then one macrotask (2). This is the fundamental event loop order.
Yes. The event loop drains all microtasks before rendering. If microtasks take too long, the paint is delayed. Keep microtasks short to maintain smooth rendering.
No. The event loop is part of the host environment (browser or Node.js). The JS engine (V8) has the call stack and heap. The event loop, Web APIs, and queues are provided by the host.
Still have questions?
Browse all our FAQs or reach out to our support team
