Published on

Debounce in JavaScript

const debounce = (func, duration = 2000) => {
	let timeout;

	return function(...args) {
		const effect = () => {
			timeout = null;
			return func.apply(this, args)

		timeout = setTimeout(effect, duration);

export default debounce;


import debounce from 'utils/debounce'

const handler = debounce(() => console.log('I will print after 4 seconds'), 4000)


Output for debounce
Output for debounce

Updates straight in your inbox!

A periodic update about my life, recent blog posts, TIL (Today I learned) related stuff, things I am building and more!

No spam - unsubscribe at any time!

Share with others