js-event-loop.md
· 727 B · Markdown
Ham
# Explaining the JavaScript Event Loop in Interviews
A short, accurate answer:
JavaScript runs one call stack. When it's empty, the event loop first drains the **microtask queue** (resolved promises, `queueMicrotask`), then takes the next **macrotask** (timers, I/O, UI events).
So this logs `A, D, C, B`:
```js
console.log('A');
setTimeout(() => console.log('B'));
Promise.resolve().then(() => console.log('C'));
console.log('D');
```
Mention that long synchronous work blocks rendering, and how you'd split it (chunking, web workers).
---
*Disclosure: I work on Linkjob AI. If you'd like real-time help in live interviews, see [AI help for online coding assessments](https://www.linkjob.ai/coding-interview-copilot/).*
Explaining the JavaScript Event Loop in Interviews
A short, accurate answer:
JavaScript runs one call stack. When it's empty, the event loop first drains the microtask queue (resolved promises, queueMicrotask), then takes the next macrotask (timers, I/O, UI events).
So this logs A, D, C, B:
console.log('A');
setTimeout(() => console.log('B'));
Promise.resolve().then(() => console.log('C'));
console.log('D');
Mention that long synchronous work blocks rendering, and how you'd split it (chunking, web workers).
Disclosure: I work on Linkjob AI. If you'd like real-time help in live interviews, see AI help for online coding assessments.