Engrain by ByteRush

JS.01 7 concepts · 7 ready

The event loop

Predict the order of any mix of sync code, promises, timers, rendering and Node callbacks.

  1. JS.01.01Call stack and run-to-completionCoreJunior9 min
  2. JS.01.02Tasks (macrotasks) and the task queueCoreJunior9 min
  3. JS.01.03Microtasks: promises, queueMicrotask, MutationObserverCoreJunior10 min
  4. JS.01.04Rendering steps: requestAnimationFrame and framesCoreMid-level10 min
  5. JS.01.05async/await in the event loopCoreMid-level10 min
  6. JS.01.06The Node.js event loop and its phasesCoreMid-level11 min
  7. 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

  1. Explain the event loop. What is the difference between a task (macrotask) and a microtask?
  2. What is the output of: console.log(1); setTimeout(()=>console.log(2)); Promise.resolve().then(()=>console.log(3)); console.log(4); and why?
  3. Is the promise executor synchronous or asynchronous?
  4. What happens if a microtask keeps queueing new microtasks?
  5. Where does requestAnimationFrame run relative to tasks and microtasks?
  6. Why is setTimeout(fn, 0) not really 0 ms?
  7. What is the difference between process.nextTick, setImmediate and setTimeout(fn, 0) in Node?
  8. List the phases of the Node.js event loop.
  9. How would you keep a page responsive while doing heavy computation?
  10. How does await work under the hood in terms of the event loop?
  11. Why do UI updates not appear until a long synchronous function finishes?