🟢 EasyPerformance📖 Theory Question

What are debounce and throttle? When do you use each?

💡

Hint

Debounce=wait for pause; throttle=limit rate

Full Answer

  • Debounce — fires AFTER user stops triggering. Best for: search input, resize, form validation
  • Throttle — fires at most once per interval. Best for: scroll, mouse move
function debounce(fn, delay) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), delay);
  };
}
const onSearch = debounce((q) => fetchResults(q), 300);
💡 Debounce = waits for storm to pass. Throttle = steady drip.

More Performance Questions

🟢 EasyWhat causes memory leaks in JavaScript and how do you detect them?→🟢 EasyWhat is the difference between reflow and repaint, and how do you avoid layout thrashing?→🟡 MediumWhat is lazy loading and code splitting?→

Practice this in a timed sprint →

5 free questions, no signup required

âš¡ Start Sprint