Use debounce for search input, auto-save, and window resize (run after activity stops). Use throttle for scroll, mousemove, and continuous events (run at a controlled rate, not after stopping).
When should you use debounce vs throttle?
More FAQs in Debouncing vs Throttling in JavaScript
Debounce delays execution until activity stops (only the last call runs). Throttle limits to once per interval (calls at a fixed rate, ignoring calls in between). Debounce = wait then run; throttle = run at most every N ms.
function debounce(fn, delay) { let timer; return function(...args) { clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), delay); }; }. Each call clears and resets the timer. Only the last call executes.
function throttle(fn, delay) { let last = 0; return function(...args) { const now = Date.now(); if (now - last >= delay) { last = now; fn.apply(this, args); } }; }. Execute only if enough time has passed since the last execution.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.