DEV Community

Takuya Kikuchi
Takuya Kikuchi

Posted on

JavaScript - Debounce

What is debounce

Waiting until a certain amount of time has passed before triggering an event

Use cases examples

  • search box
  • auto saving input

Key points

  • utilize setTimeout() and clearTimeout()
  • clearTimeout() at the beginning so that when we get an event repeatedly, reschedule triggering a callback

Demo

Reference

This article by Josh Comeau explains the details very well!
debounce snippet function in modern es6 vanilla JavaScript

Discussion (0)