Skip to solution
hardFrontend

How do you implement a throttle function?

660 views
01

Understand the problem

Question presented to candidate: "Implement a throttle function from scratch. Walk me through why it caps the call rate, then show me it actually limiting a burst of rapid calls."

What a strong answer should cover:

  • A closure holding a boolean cooldown flag (or, in an alternative implementation, a "last run timestamp").
  • On each call: if currently in cooldown, ignore the call entirely; otherwise run the wrapped function immediately and enter cooldown for the configured interval.
  • This means the FIRST call in a burst fires immediately (the "leading edge") by default, unlike debounce which always waits.
  • The cooldown-flag version and the last-run-timestamp version are both correct, common implementations with a real tradeoff between them, not just stylistic variants.
  • Real verification: proving with actual timestamps that a rapid burst produces a genuinely capped number of effect calls, spread at roughly the configured interval.

Clarifying questions expected:

  • "Should this fire on the leading edge, the trailing edge, or both?" (a strong candidate flags that the simplest version only does leading, and that configurable edges are a natural, common follow-up)

Code / implementation expected: Yes — a full working throttle implementation, executed with a rapid-fire burst and real observed timestamps proving the capped call rate.

throttle
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

JSThrottle from scratch: 15 rapid calls capped to 4 (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 139 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track