Delays a function until calls stop for N ms. Replaces Lodash debounce with 8 lines.
Updated 3 Nov 2026
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}