knaxuslearn · build · ship

Roadmaps / JavaScript / Phase 1

Phase 1 of 4 · Study weeks 1-4

The language, the event loop and bounded concurrency

This phase makes the first checkpoint possible: a fetch core that never runs away, stops when told and shows when it blocks.

Topics every week

  1. Week 18 h
    • Values, coercion and equality
    • Scope, closures and hoisting
    • this and prototypes
    • Property order and the spec's own algorithms

    Hand inA catalogue of 20 traps, each with a node:test case and the rule that explains it

  2. Week 28 h
    • Iterators, generators and symbols
    • Promises and the microtask queue
    • async and await error handling
    • Promise combinators and what they do with losers

    Hand inA small async toolkit (retry, timeout, map with limit) with tests for each failure

  3. Week 38 h
    • The Node event loop phases and the browser's task and render cycle
    • process.nextTick, microtasks and starvation
    • monitorEventLoopDelay
    • Blocking work and chunking

    Hand inA starvation lab and a delay report with your prediction beside the result

  4. Week 48 h
    • Concurrency limits and per-key queues
    • AbortSignal, AbortSignal.timeout and AbortSignal.any
    • Backpressure and load shedding
    • Little's law for sizing

    Hand inCheckpoint 1: the fetch core, its tests and the worked-reference table

Practice projects

  • Practice 1, the trap catalogue (Weeks 1 and 2): write 20 expressions that surprise experienced engineers and explain each one. Done when: every entry has a test that asserts the surprising result and a one-line rule, and at least five cite a section of the ECMAScript specification.
  • Practice 2, microtask starvation (Week 3): write code that delays timers by 200 ms or more with a microtask loop, then fix it. Done when: a delay histogram shows the stall before and p99 of 20 ms or less after, and you can say why a setImmediate yield fixes it and a second promise does not.
  • Practice 3, a bounded queue (Week 4): build a queue with a limit, per-key fairness and cancellation. Done when: 5,000 tasks queued at once never run more than the limit, memory stays flat, and a cancelled task never starts.
  • Optional, a generator-based scheduler: run cooperative tasks with generators. Done when: two tasks interleave deterministically and a test proves the order.

GitHub repos to study

Existence, last commit and README notices were checked on 22 Nov 2026 by shallow clone. Every repository below had a commit in the last six months. Archive status comes from the README, not from the GitHub setting, so look again before you rely on one.

RepoWhat to readWeek
tc39/ecma262The algorithm for each trap in your catalogue1
getify/You-Dont-Know-JSThe 2nd edition chapters on scope, closures and this1
tc39/test262How the language is tested: read the tests for one feature2
nodejs/nodeThe lib/ timer and task-queue code, to see where microtasks drain3
libuv/libuvThe event loop documentation and uv_run3

Milestone checkpoint

Build the fetch core (Checkpoint 1 above). Write the test harness first: a local fake server with hung, slow and fast hosts, and a counter that records the highest number of requests in flight. Then add the limits, the timeout and abort propagation. Finish by adding the delay monitor to the test run and the seeded 200 ms loop that must fail it. Hand in the worked-reference table with your own numbers and ADR-1 and ADR-2.

Check yourself

Answer each question in your head first, then open it to check.

  1. In a CommonJS main module, in what order do setTimeout(f, 0), setImmediate(g), Promise.resolve().then(h) and process.nextTick(k) run?
    k, then h, then f and g in an order Node does not guarantee from the main module. (In an ES module h can run before k, because module evaluation itself runs inside a promise job.)
  2. Why is a for loop with await over 100 URLs slow, and why is Promise.all over 100,000 URLs dangerous?
    Serial awaits add every latency together. Unbounded fan-out opens too many sockets and holds every result in memory. Use a pool with a limit.
  3. What does AbortSignal.timeout(5000) stop, and what does it leave running?
    It aborts operations that accept the signal, such as fetch and streams. Work that ignores the signal, including synchronous code, keeps running.
  4. Why report event-loop delay at p99 and not the mean?
    Delay measures how long synchronous work blocks the loop. The mean hides the rare long stall that users feel as a slow response.
  5. Why can a microtask loop freeze timers while a loop of setImmediate calls does not?
    The microtask queue drains completely before the loop moves on, so microtasks that keep scheduling microtasks never let it advance. A setImmediate callback that schedules another runs on the next loop turn, so timers and I/O still get a turn.