AniUI Academy
medium+250 XPPractice Available

Write debounce from scratch

A debounced function waits until the calls stop coming before it actually runs.

Implement debounce(fn, wait) returning a new function that delays calling fn until wait milliseconds have passed without another call.

What it has to do

  • Reset the timer every time the debounced function is called again.
  • Call fn with the arguments from the most recent call.
  • Preserve this when the debounced function is used as a method.
  • Expose a .cancel() that stops a pending call.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

4 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.