Write a Debounce
Talk it through out loud with your AI coach.
The problem
- medium
- Pro
A resize handler recalculates a chart hundreds of times while the user drags the window. Explain how you'd write a debounce function that only runs the work once the user has stopped for a quarter of a second, and how it differs from throttling.
What a strong answer covers
- How the wrapper remembers and resets its timer between calls.
- Passing the right arguments through when the work finally runs.
- How debouncing differs from throttling, and when each suits.
- Refinements such as cancelling on cleanup or firing at the start.
Common mistake: Creating a fresh debounced function on every event, so each one has its own timer and nothing is ever debounced.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud