Skip to solution
mediumNetflixFrontend2024 · 2022

Debounce vs throttle — implement debounce

3.7k views
01

Understand the problem

Question presented to candidate: "Implement a debounce function from scratch. Walk me through why it works, then show me it actually collapsing a burst of rapid calls into one."

What a strong answer should cover:

  • A closure holding a single timer id across calls.
  • Every call clears the previous pending timer, then starts a brand-new one — this is the entire mechanism.
  • The wrapped function only actually runs once no new call has arrived within the delay window, and it runs with the arguments from the LAST call, not the first.
  • Correct this handling if the debounced function needs to be used as a method (use a regular function for the wrapper and fn.apply(this, args), not an arrow function, if the caller relies on dynamic this).
  • Real verification: proving with actual timestamps that a rapid burst produces exactly one effect call, not an assumption from reading the code.

Clarifying questions expected:

  • "Should the debounced function support being called as an object method (i.e. does this need to work), or is a plain top-level function enough?"
  • "Do you want a .cancel() method as part of this, or is that a separate follow-up?" (confirms scope — the advanced .cancel() variant is a distinct question in this bank)

Code / implementation expected: Yes — a full working debounce implementation, executed with a rapid-fire burst and real observed timestamps proving only the last call's effect fires.

javascriptperformance
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript / frontend-implementation interview questions. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every result below was actually run on Node.js v24.19.0 — the print

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSDebounce from scratch: 5 rapid calls collapse into 1 (run directly)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 42 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track