Debounce vs throttle

Debounce and throttle interview questions

Debounce and throttle are among the most common JavaScript utility questions in frontend interviews. Master both implementations, know when to use each, and connect them to real UI rounds like autocomplete and infinite scroll.

Start by explaining the behavioral difference in one sentence, then implement the simpler version, then add leading/trailing options if the interviewer pushes.

After the utility works, practice applying it inside a React machine coding challenge so you can talk about product usage, not only timer mechanics.

Practice throttlePractice debounce

Choose the right tool

Wrong choice is a common interview fail. Match the utility to the event pattern and UX expectation.

  • Debounce when you want “after typing stops”
  • Throttle when you want “steady updates”
  • Cancel in-flight work when inputs change

Implementation checklist

Closures hold timer state. Be explicit about whether the first call fires immediately and how trailing calls behave.

  • clearTimeout / clearInterval hygiene
  • Leading and trailing edges
  • this and argument forwarding

Connect to UI rounds

Interviewers love follow-ups that move from utility to product. Be ready to drop debounce into search and throttle into scroll.

  • Autocomplete search box
  • Infinite scroll sentinel
  • Window resize layout recalculation

Debounce, throttle, and related utilities

Recommended next pages

FAQ

What is the difference between debounce and throttle?

Debounce waits until events stop for N milliseconds before running (great for search input). Throttle runs at most once per N milliseconds while events continue (great for scroll and resize).

Why do frontend interviews ask debounce/throttle?

They test closures, timers, leading/trailing edge behavior, and whether you can choose the right rate-limiting tool for a UI problem.

Where are these used in real products?

Debounce: typeahead search, form autosave. Throttle: scroll listeners, window resize, mousemove tracking, infinite-scroll checks.

What follow-ups should I expect?

Implement leading vs trailing edges, cancel/flush APIs, and explain how you would use them inside an autocomplete or infinite-scroll component.