JavaScript runtime & language mechanics
How JavaScript runs your code: one thread, the event loop, promises and cancellation, plus how DOM events and memory work.
7 lessons
Async execution model
- 1Run-to-completion on one threadA running task is never set down for another: whatever arrives waits its turn, and a long task makes everything wait.
- 2Promise states: pending, fulfilled, rejectedA promise holds one result: the first resolve or reject wins, a thenable is followed, and reactions always run later.
- 3Promise combinators and concurrency limitsCombinators decide when you hear back, not what keeps running. Cancelling needs an AbortSignal, and a concurrency cap needs a pool.
- 4Cancellation and out-of-order responsesPromises cannot be cancelled, so you abort cooperatively through a signal, or ignore stale responses; either way the server keeps working.
- 5Debounce vs throttleDebounce waits for quiet and fires once; throttle fires on a steady beat while the noise continues. They answer different questions.