Debounce vs Throttle in JavaScript — What's the Difference?
Debounce delays a function until activity stops; throttle limits it to run at most once per interval. Learn when to use each with code examples.
Published September 16, 2026
Debounce waits until activity stops before running a function; throttle runs it at most once per time interval no matter how much activity there is. Debounce suits search boxes, throttle suits scroll and resize handlers.
The concept
Debounce resets a timer on every call. The function fires only after the calls have been quiet for the delay, so a burst of 20 keystrokes triggers a single run at the end.
Throttle guarantees a steady rate: the first call runs, then further calls are ignored until the interval elapses. A 100 ms throttle on a scroll handler runs at most 10 times per second.
Events over time
Practical examples
Debounce implementation
function debounce(fn, delay) {
let t
return (...args) => {
clearTimeout(t)
t = setTimeout(() => fn(...args), delay)
}
}
input.addEventListener('input', debounce(search, 300))Throttle implementation
function throttle(fn, interval) {
let last = 0
return (...args) => {
const now = Date.now()
if (now - last >= interval) { last = now; fn(...args) }
}
}
window.addEventListener('scroll', throttle(onScroll, 100))Which one for which job
Search-as-you-type, form validation, auto-save: debounce. Scroll position, mouse move, window resize, game input: throttle.
type → debounce(300ms)
scroll → throttle(100ms)Common mistakes
- Creating the debounced function inside a render or handler so every call gets a fresh timer.
- Choosing debounce for scroll tracking, which only updates after the user stops.
- Setting the delay too long so the UI feels laggy.
Key takeaways
- Debounce = run after quiet; throttle = run at most every N ms.
- Create the wrapped function once, not per event.
- Libraries like lodash provide both with leading/trailing options.
FAQ
Can I run on the first call instead of the last?
Yes, a leading-edge debounce fires immediately and then ignores calls until quiet. lodash.debounce has a leading option.
Do they replace requestAnimationFrame?
For visual updates, requestAnimationFrame is often better than a time-based throttle.