setTimeout and setInterval schedule work. Debounce waits for pause before firing (search boxes); throttle caps rate (scroll handlers).
Debounce
Reset timer on each keystroke—handler runs once user stops typing.
clearTimeout
Always clear timers on component teardown in SPAs to avoid leaks.
Important interview questions and answers
- Q: Debounce vs throttle?
A: Debounce: last event wins after delay; throttle: at most once per window. - Q: setInterval drift?
A: Not precise for animation—use requestAnimationFrame.
Self-check
- When debounce search input?
- Why clear timeout on unmount?
Tip: Re-run the playground code for timers-debounce-preview and tweak one line before the MCQs.
Interview prep
- Debounce?
Run handler after events stop for a delay.