function debounce(fn, delay) { let timer; return function(...args) { clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), delay); }; }
Debounce Interview Questions (Flipkart)
How do you implement debounce from scratch (Flipkart question)?
The answer
More FAQs in Debounce Interview Questions (Flipkart)
Debounce delays execution until activity stops (search input, only the last call runs). Throttle limits to once per interval (scroll handler, calls at most once per N ms).
Use jest.useFakeTimers() to control time. Call the debounced function multiple times, advance the timer by the delay, and verify only the last call's callback executed.
Attach a cancel property: debounced.cancel = () => clearTimeout(timer). Call debounced.cancel() to cancel the pending execution.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.