JavaScriptAdvanced#performance#functions

What is debouncing and throttling?

Debouncing delays the call until activity stops for a set time — good for search inputs. Throttling guarantees at most one call per interval — good for scroll and resize handlers.

Example
function debounce(fn, ms) {
  let t;
  return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), ms); };
}
input.oninput = debounce(search, 300);

Related Questions

1
JavaScriptBeginner#arrays

Explain map, filter and reduce.

Open
2
JavaScriptBeginner#arrays

Difference between forEach and map?

Open
3
JavaScriptBeginner#arrays

Difference between slice and splice?

Open