JavaScript · Middle · Question 26 of 75
What is requestAnimationFrame for?
- ✓Correct answer: To run code before the next repaint - for smooth animations
- 2To request the next video frame from the server for a player
- 3To run code in a Web Worker without blocking the page
Explanation
The callback is synced with the screen refresh rate and isn't called in background tabs, saving resources. Animation via setTimeout(fn, 16) can drift out of sync with frames and stutter.