Advertisement
Advanced JavaScript, DOM & Events

What is the difference between passive and non-passive event listeners for scroll performance?

Short answer

A passive listener ({ passive: true }) tells the browser up front that it will never call preventDefault(), letting the browser start scrolling immediately without waiting for the handler to finish — significantly improving scroll smoothness for touch/wheel events.

Save JavaScript mock interview
Advertisement
AModel answer
A passive listener ({ passive: true }) tells the browser up front that it will never call preventDefault(), letting the browser start scrolling immediately without waiting for the handler to finish — significantly improving scroll smoothness for touch/wheel events.
el.addEventListener('touchstart', handleTouch, { passive: true });
Real-world example
Fixing janky scrolling on mobile caused by a touchstart/touchmove listener that doesn't actually need to block scrolling.
Likely follow-ups
  • What happens if a passive listener DOES call preventDefault() anyway?
Related topics