Timers, Debounce and Throttle — Concept Check
Questions on Timers, Debounce and Throttle. setTimeout and setInterval schedule work; debounce and throttle limit how often it happens. Both patterns are closures, and both need cleanup.
Questions in this quiz
7 questions on Timers, Debounce and Throttle — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A user complains that a search input on your website is sending too many requests as they type. Which technique should you implement to address this?
- ADebounce the search input handler
- BUse requestAnimationFrame for the search input
- CUse setInterval for the search input
- DThrottle the search input handler
2.You notice that a React component with a setInterval timer is causing memory leaks. What is the most likely cause?
- AThe interval is not cleared on component unmount
- BThe interval delay is too short
- CThe component is re-rendering too often
- DThe interval function is incorrect
3.Which scenario is best suited for using throttle instead of debounce?
- ASubmitting a form after a pause
- BHandling window resize events
- CUpdating a search result as the user types
- DAutosaving a document after typing stops
4.A developer uses setTimeout to schedule a function but notices it doesn't run after the specified delay. What might be happening?
- AThe delay is too short
- BThe function is not defined
- CThe timer is not set correctly
- DThe function is blocked by other code
5.Which of the following is true about debounce?
- AIt runs at a fixed interval regardless of calls
- BIt is used to handle animation frames
- CIt waits for a pause in calls before running
- DIt runs immediately on the first call
6.You have a function that updates the UI based on scroll position. Which technique ensures it doesn't update too frequently?
- AThrottle the scroll event handler
- BUse clearInterval for the scroll event
- CUse setTimeout for the scroll event
- DDebounce the scroll event handler
7.In what situation would using requestAnimationFrame be more appropriate than debounce or throttle?
- AUpdating a counter every second
- BAnimating a parallax effect on scroll
- CAutosaving a document
- DHandling input in a search box