1
JavaScriptBeginner#arrays
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.
function debounce(fn, ms) {
let t;
return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), ms); };
}
input.oninput = debounce(search, 300);