Throttles a function to run at most once every specified delay

Version
  • 2.0.0

Example

// Throttle a scroll event handler
const throttledScroll = throttle(() => {
   console.log('Scroll event throttled');
}, 1000);

// Add the throttled function as an event listener
window.addEventListener('scroll', throttledScroll);

// Now, the console will log at most once every 1000ms during scrolling