Skip to content

Use Cases

Choose debounce or throttle based on the behavior you need.

// Debounce: Search, form validation, resize
const search = debounce(fetchResults, 300);
input.addEventListener('input', search);
const validate = debounce(validateField, 500);
input.addEventListener('input', validate);
const resize = debounce(recalculateLayout, 200);
window.addEventListener('resize', resize);
// Throttle: Scrolling, mouse movement, game inputs
const scroll = throttle(updateProgressBar, 50);
window.addEventListener('scroll', scroll);
const mouseMove = throttle(trackMousePosition, 16); // ~60fps
document.addEventListener('mousemove', mouseMove);
ScenarioUseWhy
Search autocompleteDebounceWait until user stops typing
Form validationDebounceValidate after user finishes
Window resizeDebounceRecalculate after resize ends
Scroll positionThrottleUpdate at regular intervals
Mouse trackingThrottleSample at consistent rate
Game inputThrottleCap actions per second
Save buttonLeading debounceSave immediately, prevent double-save
  • Debounce: “Wait until they stop, then act”
  • Throttle: “Act at most this often”
  • Leading debounce: “Act now, then wait”
  • Choose based on whether you need the final result or regular updates