BeginnerCoder

Lesson 22 — Debounce

Wait until the calls stop

Debounce delays a function until the calls stop for a moment. Each new call cancels the previous timer (clearTimeout) and starts a new one (setTimeout). So if a user types "c", "ca", "cat" quickly, only "cat" triggers the search.

const id = setTimeout(() => console.log("later"), 500);
clearTimeout(id);   // cancelled: nothing is logged

...args passes on all the arguments the call received.

Why it matters: without debounce, a search box sends one request per keystroke.

Want it another way?
Task

Inside the returned function, cancel the old timer and start a new one, so only "cat" is searched.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with JavaScript Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.