The event loop
Predict the order of any mix of sync code, promises, timers, rendering and Node callbacks.
- JS.01.01Call stack and run-to-completionCoreJunior9 min
- JS.01.02Tasks (macrotasks) and the task queueCoreJunior9 min
- JS.01.03Microtasks: promises, queueMicrotask, MutationObserverCoreJunior10 min
- JS.01.04Rendering steps: requestAnimationFrame and framesCoreMid-level10 min
- JS.01.05async/await in the event loopCoreMid-level10 min
- JS.01.06The Node.js event loop and its phasesCoreMid-level11 min
- JS.01.07Scheduling and yielding to the main threadCoreSenior11 min
Practice rooms
- Output puzzle workshop20 puzzles (rung 4 timed) + spaced re-solve deck
Interview questions in this module
- Explain the event loop. What is the difference between a task (macrotask) and a microtask?
- What is the output of:
console.log(1); setTimeout(()=>console.log(2)); Promise.resolve().then(()=>console.log(3)); console.log(4);and why? - Is the promise executor synchronous or asynchronous?
- What happens if a microtask keeps queueing new microtasks?
- Where does
requestAnimationFramerun relative to tasks and microtasks? - Why is
setTimeout(fn, 0)not really 0 ms? - What is the difference between
process.nextTick,setImmediateandsetTimeout(fn, 0)in Node? - List the phases of the Node.js event loop.
- How would you keep a page responsive while doing heavy computation?
- How does
awaitwork under the hood in terms of the event loop? - Why do UI updates not appear until a long synchronous function finishes?