Stas Kyaune’s Post

Most frontend devs use debounce and throttle interchangeably. They're not the same thing. Debounce — waits until the user stops doing something, then fires once. Throttle — fires at a fixed interval while the user is doing something. The mental model that sticks: Debounce = "wait for the silence" Throttle = "fire on the beat" Where people mess this up: ❌ Throttle on a search input → results lag behind what the user typed ❌ Debounce on a scroll handler → your progress bar freezes mid-scroll The rule: → Search / autocomplete → debounce → Scroll / resize / mousemove → throttle → Button that triggers an API call → debounce No lodash needed. Wrong choice doesn't throw — it just makes your app feel slightly off. Users notice, even if they can't explain why. #JavaScript #Frontend #WebDevelopment #CodeQuality

  • text

Nice man! A minor edge case that normally shows up in debounce is the loss of this context using your approach. Imagine the debounce used as a method on an object — it would silently fail because the returned arrow function captures this lexically, not from the caller. A simple fix is returning a regular function(...args) instead, and making sure the inner setTimeout uses an arrow function so it inherits this from the outer one — then func.apply(this, args) works correctly.

  • No alternative text description for this image

"Silence vs beat" is such a clean mental model 👌

See more comments

To view or add a comment, sign in

Explore content categories