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
Debounce vs throttle
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.
Wrong choice is a common interview fail. Match the utility to the event pattern and UX expectation.
Closures hold timer state. Be explicit about whether the first call fires immediately and how trailing calls behave.
Interviewers love follow-ups that move from utility to product. Be ready to drop debounce into search and throttle into scroll.
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).
They test closures, timers, leading/trailing edge behavior, and whether you can choose the right rate-limiting tool for a UI problem.
Debounce: typeahead search, form autosave. Throttle: scroll listeners, window resize, mousemove tracking, infinite-scroll checks.
Implement leading vs trailing edges, cancel/flush APIs, and explain how you would use them inside an autocomplete or infinite-scroll component.