JavaScript 2025 · Promises and fetch

Debounce a function

Run a function only after calls stop for a moment, for example on search input.

function debounce(fn, delay) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), delay);
  };
}

Official JavaScript 2025 documentation

More promises and fetch commands

All promises and fetch commands · JavaScript 2025 cheatsheet

Was this page helpful?