---
title: "What is debouncing and throttling, and when do I use each?"  
description: "What is debouncing and throttling, and when do I use each?"  
author: "Federica Bianchi"  
published: 2026-11-13  
updated: 2026-11-13  
canonical: https://www.mindstick.com/forum/163016/what-is-debouncing-and-throttling-and-when-do-i-use-each  
category: "JavaScript and Frontend"  
tags: ["javascript", "debounce", "throttle", "performance", "events"]  
reading_time: 1 minute  

---

# What is debouncing and throttling, and when do I use each?

My search box fires an API call on every keystroke. People tell me to debounce. What is that, and how is it different from throttle?

## Replies

### Reply by Vaibhav Kumar

Both limit how often a function runs when an event fires rapidly.

- **Debounce**: wait until the events stop for a set time, then run once. A search box is the classic case: run the search 300 ms after the user stops typing.
- **Throttle**: run at most once every N milliseconds while the events keep coming. Good for scroll, resize or mouse-move handlers.

A simple debounce:

```
function debounce(fn, delay) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), delay);
  };
}
```

Use debounce for "act when they pause" and throttle for "act regularly during the activity". In real projects you can use a tested helper such as the ones in lodash. Also cancel in-flight requests so an old response cannot overwrite a newer one.


---

Original Source: https://www.mindstick.com/forum/163016/what-is-debouncing-and-throttling-and-when-do-i-use-each

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
