Patterns
Recurring designs and idioms.
- API Design for Libraries (Fluent APIs, Diagnostics, Source Maps)Designing a chainable fluent API that defers work to a clear terminal call, actionable diagnostics, and source maps that keep debugging transformed code usable.
- Architectural Decision Records (ADRs)A short, durable document capturing one significant architectural decision's context, choice, and consequences, written at the time it's made.
- Arrange / Act / AssertA structure for writing a clear unit test โ set up the input, run the code under test, check the result.
- AST Fundamentals (Parse, Transform, Generate)Every source-to-source tool follows the same pipeline โ parse code into a structured Abstract Syntax Tree, transform it, generate code back out.
- Benchmark DesignWarm-up, representative input, variance reporting, and guarding against dead-code elimination โ what separates a trustworthy benchmark from a misleading number.
- Big O Notation (in Everyday Code)A way to describe how a piece of code's cost grows as its input grows โ most usefully spotted as a loop nested inside another loop over related data.
- CallbacksA function passed as an argument to another function, to be called later โ the pattern behind array methods, events, and async code.
- Closures for EncapsulationUsing a closure deliberately to create private state โ a factory function returning an object whose internal variables can't be reached from outside.
- CodemodsA program that transforms source code programmatically via its AST โ a scripted, repeatable refactor applied across an entire codebase.
- CommonJS versus ES ModulesNode's two module systems โ require/module.exports (CommonJS) and import/export (ES modules) โ and how Node decides which one a file uses.
- Dependency InversionDepending on a passed-in interface rather than a concrete, hard-coded implementation โ what makes substituting a test double possible.
- Dynamic Evaluation Risks (eval, new Function)eval and new Function execute a string as code with full access to their reachable scope โ neither provides a meaningful sandbox boundary.
- Event DelegationAttaching one listener to a stable ancestor, using event bubbling to handle events from any current or future descendant.
- Function CompositionChaining small, single-purpose functions into a pipeline, each handling one transformation.
- Generational Garbage CollectionMost modern engines organize the heap by object age, since most objects die young โ collecting the young generation frequently and cheaply, the old generation less often.
- Generator Delegation (yield*)Delegates part of a generator's iteration to another iterable, forwarding values and the delegate's return value transparently.
- Guard ClausesHandling an edge case with an early return at the top of a function, instead of nesting the normal-case logic inside a conditional.
- Hidden Classes and Inline CachesEngine-dependent optimizations that track an object's shape and cache property-access paths โ consistent object shapes keep them effective.
- HTTP Caching (Cache-Control)How the Cache-Control header controls whether and how long a response can be reused without asking the server again.
- Integrity Levels (preventExtensions, seal, freeze)Three levels of object mutability restriction, each blocking a specific, increasing set of operations โ freeze is shallow.
- JSDoc AnnotationsComment-based type annotations that give editor tooling a function's real contract, with no build step required.
- Live Bindings and Module CyclesAn ES module import is a continuously updated reference, not a copied value โ the mechanism that makes many circular imports resolvable.
- MemoizationCaching a pure function's results, keyed by its arguments, so a repeated call with the same input returns instantly instead of recomputing.
- Memory Leak SourcesFour classic causes of a JavaScript memory leak โ forgotten listeners, uncleared timers, long-lived closures, and detached DOM nodes still referenced.
- Mutation TestingIntroduces small bugs into code and reruns the test suite, checking whether tests actually catch them โ measuring test quality beyond what coverage can show.
- Node's Event Loop PhasesNode's event loop cycles through distinct phases (timers, poll, check, and others), each handling a specific callback category โ microtasks still drain between every phase.
- Observability Basics (Structured Logs, Correlation IDs)Understanding a system's internal state from its external outputs โ structured logs and a correlation id threaded through a request's full call chain.
- Plugin Systems and Isolation BoundariesLetting third-party code extend a tool's behavior, deliberately, through only the specific capabilities a plugin's job actually requires.
- Ports and Adapters (Hexagonal Architecture)Isolates core logic behind interfaces (ports) it depends on, with concrete I/O implementations (adapters) plugged in from outside.
- Proper Tail CallsA specified stack-frame-reuse optimization for tail-position calls, implemented by Safari's JavaScriptCore but not V8 or SpiderMonkey โ not reliable for stack safety in practice.
- Property-Based TestingStates an invariant that should hold for any valid input, and generates many varied inputs (including edge cases) to check it, shrinking failures to a minimal reproducer.
- Prototype PollutionAttacker-controlled data used to set a property on Object.prototype itself, affecting every plain object in the program โ distinct from DOM XSS.
- Prototypes and Object.createEvery object delegates to another object via its prototype; Object.create sets that link up explicitly.
- Proxy and ReflectProxy intercepts fundamental object operations through traps; Reflect provides each operation's default implementation for a trap to delegate to.
- Reading Specification AlgorithmsHow to read the ECMAScript specification's numbered-step, abstract-operation style, including completion records and the ? abrupt-completion shorthand.
- Regular Expressions (Introduction)What problem a regular expression solves โ matching a pattern of text, not one exact value โ without full pattern-writing fluency yet.
- Retry with Exponential BackoffRetrying a failed, idempotent operation with an increasing delay between attempts, to avoid hammering a struggling server.
- Semantic VersioningA version-numbering convention (major.minor.patch) that promises what kind of change a release contains, based on its effect on consumers.
- Structured ConcurrencyBinding a concurrent operation's lifetime to its parent's, so cancelling the parent explicitly propagates to every child it started.
- Supply-Chain Security for DependenciesA dependency is a trust decision beyond its current code โ provenance, transitive dependency count, update risk, and install-time script execution all matter.
- Test Doubles (Stub, Mock, Fake)Three kinds of substitute for a real dependency in a test โ a stub returns data, a mock asserts on calls, a fake is a real simplified implementation.
- The Dual-Package HazardShipping both a CommonJS and ESM build risks an app loading two separate instances of the same package, with two separate copies of any module-level state.
- The Event Loop (Microtasks and Macrotasks)The call stack, and the two queues โ microtasks and macrotasks โ the event loop drains, always fully emptying microtasks before touching the next macrotask.
- The TC39 Stage ProcessHow a proposal advances through five stages (0-4) toward becoming a standardized ECMAScript feature, and the compatibility responsibility each stage implies.
- The Test PyramidA heuristic about cost and confidence โ more unit tests, fewer integration tests, fewer still end-to-end tests โ not a strict ratio to enforce.
- Threat ModelingIdentifying a system's assets, actors, and trust boundaries โ even an informal version done deliberately catches bug classes a functional review misses.
- Throttle and DebounceTwo techniques for limiting how often expensive work runs in response to a high-frequency event โ throttle caps the rate, debounce waits for a pause.
- Throwing at a Validation BoundaryValidate input where it enters your code and throw a descriptive Error, so bad values can't silently propagate deeper into the program.