Debounce Function in JavaScript

A utility function that limits how often a function can fire, useful for search input or resize events.

An Nguyễn VănAn Nguyễn Văn
November 10, 2025
65 views
0 saves

Code

1function debounce(fn, delay = 300) {
2  let timeout;
3  return (...args) => {
4    clearTimeout(timeout);
5    timeout = setTimeout(() => fn(...args), delay);
6  };
7}
8

About the Author

An Nguyễn Văn

An Nguyễn Văn

@an-nguyen-99

Test tiểu sử 3

View Profile