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

Explaining the JavaScript Event Loop in Interviews

linkjobai ревизій цього gist 5 days ago. До ревизії

1 file changed, 19 insertions

js-event-loop.md(файл створено)

@@ -0,0 +1,19 @@
1 + # Explaining the JavaScript Event Loop in Interviews
2 +
3 + A short, accurate answer:
4 +
5 + 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).
6 +
7 + So this logs `A, D, C, B`:
8 +
9 + ```js
10 + console.log('A');
11 + setTimeout(() => console.log('B'));
12 + Promise.resolve().then(() => console.log('C'));
13 + console.log('D');
14 + ```
15 +
16 + Mention that long synchronous work blocks rendering, and how you'd split it (chunking, web workers).
17 +
18 + ---
19 + *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/).*
Новіше Пізніше