Остання активність 5 days ago

Explaining the JavaScript Event Loop in Interviews

Версія 8afac7e12796038f9ae55201a5795a28668977ca

js-event-loop.md Неформатований

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.