Q39: What is requestAnimationFrame() and why is it preferred over setInterval for animations?
requestAnimationFrame(cb) instructs the browser to execute a specified callback before the next repaint frame (typically 60fps/120fps). It synchronizes with hardware display refresh rates and pauses execution in inactive background tabs to conserve power.
Key Takeaways
Synchronizes animation updates directly with screen repaint frames.
Pauses automatically in hidden background browser tabs.
Knowledge Check
Why is requestAnimationFrame superior to setInterval(fn, 16) for smooth CSS/Canvas animations?