requestAnimationFrame
A web API for scheduling a function to run just before the browser's next repaint, synchronized with the screen's refresh rate. The right way to do smooth JavaScript animations — instead of setTimeout/setInterval.
Problem: animating with setInterval(fn, 16) is unreliable — the interval doesn't sync with the screen's refresh, so frames jump or double, and animations keep wasting CPU even when the tab is hidden. requestAnimationFrame(callback) asks the browser to run your callback just before the next frame, in step with the screen (60Hz, 120Hz, whatever the screen has) → smooth animation, and it automatically pauses when the tab isn't visible (saving battery/CPU). Pattern: the callback animates one step and calls rAF again for the next frame, a loop synced with the screen. Use case: all JS-driven animations, game loops, smooth scroll, canvas rendering. Complement: requestIdleCallback for non-urgent work. Rule of thumb: animate with CSS if possible (even cheaper), but when JS is needed, rAF is the right tool. Related to requestIdleCallback and will-change.