Throttling ensures a handler runs at most once per time period. Use for scroll or resize.
let lastRun = 0;
window.addEventListener("scroll", () => {
if (Date.now() - lastRun > 100) {
lastRun = Date.now();
handleScroll();
}
});
This runs at most every ms, no matter how often scroll fires.