← All Exercises
Debounce Function
intermediatejavascript
Background
Debouncing is crucial for performance optimization in search inputs, resize handlers, and button click prevention.
Problem
Write a debounce function that takes a callback and a delay in milliseconds, returning a new function that only executes the callback after the delay has passed without any new calls.
Input
A function to debounce and a wait time in milliseconds.
Output
A debounced version of the input function.
Sample tests
Sample 1
Input: fn, 300ms
Expected: fn called once after 300ms of inactivity
Your solution
Learning objective
Understand closures, timer management, and function composition for rate limiting.