Hand-rolled JS utilities

Implement debounce, throttle, promise.all, deep clone, an event emitter — from memory, with edge cases. The frontend equivalent of DSA warmups.

About 30 min read3-question knowledge check

The mental model

Hand-rolled JS utilities are the frontend equivalent of DSA warmups: implement debounce, throttle, Promise.all, a deep clone, an event emitter, curry, or a Promise from scratch — from memory, with the edge cases. You are not asked because the job requires reimplementing lodash; you are asked because **writing these correctly proves you actually understand closures, this, the event loop, and promise mechanics**, rather than having memorized that "debounce delays a function."

The analogy: a musician auditioning is asked to play scales, not because concerts are scales, but because scales expose whether the fundamentals are solid. debounce is a scale that reveals whether you understand closures and timers; Promise.all reveals whether you understand promises and async coordination; bind reveals whether you understand this. A candidate who can wire a React app but cannot implement debounce from scratch has learned the framework without the language underneath it — and these questions are designed to surface exactly that gap.

**Why this exists — what it filters for.** Every one of these utilities is a small closure over some private state, and getting the edge cases right requires knowing precisely how JavaScript's scoping, this-binding, and async queues behave. A debounce that forgets to preserve this and arguments fails when used as an event handler. A Promise.all that resolves in completion order instead of input order is subtly, dangerously wrong. A deep clone that does not handle circular references stack-overflows. The edge cases are the whole point: they are where language understanding shows through, which is why the interviewer's follow-up is always "now handle X."

The organising principle: **each utility is a closure holding private state, plus correct handling of this, arguments, and async ordering.** Get those three right and the whole category falls out.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision