Member-only story

Debounce and Throttling: What They Are and When to Use Them

Found Good article on debounce and throttling:: https://medium.com/@bs903944/debounce-and-throttling-what-they-are-and-when-to-use-them-eadd272fe0be

Let’s Connect on Preplaced.com, Book Your Free Trial!
Please SUBSCRIBE YouTube Channel: FrontEnd Interview Preparation

What is Debouncing?

Debouncing is a technique that delays the execution of a function until the user stops performing a certain action for a specified amount of time. For example, if you have a search bar that fetches suggestions from the backend as the user types, you can debounce the function that makes the API call, so that it only runs after the user stops typing for a few seconds. This way, you can avoid making too many API calls that might overload your server or return irrelevant results.

  • To implement debouncing in JavaScript, you can use a timer variable to track the delay period.
  • You can use the setTimeout function to set a timer that will execute your function after the delay period.
  • You can also use the clearTimeout function to cancel the timer if the user performs the action again before the delay period ends.
  • This way, you can ensure that your function only runs once after the user stops performing the action.

--

--

Sonika | @Walmart | Frontend Developer | 11 Years
Sonika | @Walmart | Frontend Developer | 11 Years

Responses (1)