> For the complete documentation index, see [llms.txt](https://www.logeshpaul.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.logeshpaul.com/wiki/code/what-is-debounce.md).

# What is debounce?

## **What is debounce?**

The term **debounce** comes from electronics. When you’re pressing a button, let’s say on your TV remote, the signal travels to the microchip of the remote so quickly that before you manage to release the button, it bounces, and the microchip registers your “click” multiple times.

<figure><img src="/files/UIMDvXPSyaHHXBnK9sh9" alt=""><figcaption></figcaption></figure>

To mitigate this, once a signal from the button is received, the microchip stops processing signals from the button for a few microseconds while it’s physically impossible for you to press it again.

[Codepen](https://codepen.io/ondrabus/pen/WNGaVZN?editors=1111)

```bash
function debounce(func, timeout = 300){
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => { func.apply(this, args); }, timeout);
  };
}
function saveInput(){
  console.log('Saving data');
}
const processChange = debounce(() => saveInput());
```

```bash
function debounce(func, timeINMS) {
  let timeout;

  return function () {
    clearTimeout(timeout);
    timeout = setTimeout(func, timeINMS);
  };
}

let debouncedHello = debounce(() => console.log("say hello", Date.now()), 800);
```
