How the browser draws the page · mid
requestAnimationFrame, requestIdleCallback and timers
requestAnimationFrame runs your callback right before the next paint (about 60 or 120 times a second, paused in hidden tabs), so it is for visual updates; requestIdleCallback runs low-priority work when the browser is idle; setTimeout is for time, not for animation.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- rAF callbacks run once per frame before style and layout; good for animations and batching DOM writes.
- Background tabs pause rAF and throttle timers (to about once a second or less).
- requestIdleCallback(cb, { timeout }) gives a deadline object; use for analytics or prefetch. scheduler.yield() lets long tasks give the main thread back (helps INP).
- In the event loop, rAF runs in the rendering step, after tasks and microtasks.
The red pen
Common traps: mistake → fix
Mistake: "setTimeout(fn, 16) is the same as rAF"
Fix: timers drift and are not aligned with frames, causing jank.
Easy to hard
Questions interviewers ask, easy to hard
- When would you use rAF vs setTimeout?
- What is requestIdleCallback for?
- Where does rAF run in the event loop?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.