No snippets match your search. Try a broader term like “array”, “async” or “format”.
Why “modern” JavaScript matters
Most of the snippets on this page replace patterns that needed a utility library five years ago. Deep cloning used to mean importing Lodash; formatting a date meant Moment.js; generating an ID meant a UUID package. Today structuredClone, Intl and crypto.randomUUID are built into every modern browser — shipping a library to do the same work just adds bundle weight, slows your page and widens your dependency attack surface.
Knowing what the platform now does natively is one of the clearest markers separating junior from senior frontend work. The platform team at every browser vendor has spent a decade absorbing the best ideas from userland libraries — the modern developer's job is to know they landed.
Copy less, understand more
Every snippet here is deliberately short enough to read in one sitting, and each one names the trade-off it makes. A debounce delays work at the cost of latency; event delegation saves memory at the cost of one extra DOM lookup per click; Promise.all is fast but fails as a group. Understanding the trade-off is what lets you decide when not to use a pattern — which is the skill interviews actually probe for.
All code on this page is dependency-free, framework-agnostic and safe to paste into any project — vanilla JS, React, Vue or Svelte alike. No attribution needed.
How these snippets are chosen
The 32 patterns here aren't a random grab-bag — they're the ones that come up repeatedly in code reviews, interview questions and real production debugging. Each one had to clear three bars: it must replace a pattern that is either longer, more error-prone or more dependency-heavy; it must work in every modern browser without a transpiler; and the explanation must fit in a paragraph. If a trick is genuinely useful but takes a wall of text to explain safely, it belongs in a guide, not a snippet.
New snippets are added as the JavaScript platform evolves — when a proposal moves to Stage 4 and browsers ship it, the collection grows. Object.groupBy, Array.fromAsync and the using keyword for resource disposal are the most recent additions. Patterns that become so mainstream they stop needing explanation are retired to keep the collection useful rather than encyclopaedic.