0% found this document useful (0 votes)
3 views

Denounce vs settimeout functions in JS

The document explains the concepts of setTimeout and debounce in JavaScript. setTimeout executes a function once after a specified delay, while debounce ensures a function executes only after a period of inactivity, preventing excessive calls. It provides use cases for both methods and suggests when to use each one.

Uploaded by

guru63920
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Denounce vs settimeout functions in JS

The document explains the concepts of setTimeout and debounce in JavaScript. setTimeout executes a function once after a specified delay, while debounce ensures a function executes only after a period of inactivity, preventing excessive calls. It provides use cases for both methods and suggests when to use each one.

Uploaded by

guru63920
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Debounce

setTimeout

www.scribbler.live
What is setTimeout?
setTimeout executes a function once
after a specified delay.
Example
What is Debounce?
Debounce ensures a function executes
only after a period of inactivity.
Example
A search input field that makes API
calls only after typing stops.
debounce setTimeout

Purpose

Delays execution Delays execution


until after inactivity once
Repeated
Calls

Clears previous timer Each call creates a


before starting a new timer
new one
Example
Use Cases

Preventing excessive Delaying execution


API calls (e.g., (e.g., hide a message
search inputs) after 5s)
Which One Should You
Use?

when you just need a delay


setTimeout
before running code once.

when you want to prevent


debounce
frequent function execution.
Keep Exploring
Javascript
with us!
Share this with a friend who needs it and
make sure to practice these in scribbler.

Scribbler.live
Free and Open Interface to
experiment JavaScript

You might also like