7

from the lodash documentation:

Throttle

Creates a throttled function that only invokes func at most once per every wait milliseconds

Debounce

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked

I am a little bit confused about these two definitions, it sounds that they are similar.

Can someone give us a simple explanation with examples.

zied hajsalah
  • 546
  • 1
  • 6
  • 17

1 Answers1

14

The lodash docs link to the article Debouncing and Throttling Explained Through Examples.

From that article:

The Debounce technique allow us to "group" multiple sequential calls in a single one.

debounce

By using _.throttle, we don't allow to our function to execute more than once every X milliseconds.

The main difference between this and debouncing is that throttle guarantees the execution of the function regularly, at least every X milliseconds.

The article explains the differences clearly using prose and diagrams.

joews
  • 29,767
  • 10
  • 79
  • 91
  • Good stuff, but maybe a bit too verbose. More concise summary and demos can be found in the article "The Difference Between Throttling and Debouncing" (https://css-tricks.com/the-difference-between-throttling-and-debouncing/) – TMG Jan 07 '19 at 09:40