Debouncing delays handler execution until events stop firing. Use for search inputs.
let timeout;
input.addEventListener("input", (e) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
search(e.target.value);
}, 300);
});
This waits ms after the user stops typing before searching.