A callback that runs when the browser is idle (between frames). The deadline object tells you how much time is left. Useful for low-priority work that should not cause frame drops.
setTimeout vs requestAnimationFrame vs queueMicrotask in JavaScript
What is requestIdleCallback?
The answer
More FAQs in setTimeout vs requestAnimationFrame vs queueMicrotask in JavaScript
setTimeout is a macrotask (lowest priority, runs after rendering). requestAnimationFrame runs before the next paint (for animations). queueMicrotask is a microtask (highest priority, runs before rendering and macrotasks).
For animations and visual DOM updates. requestAnimationFrame syncs with the browser's refresh rate (usually 60fps), runs before the next paint, and produces smoother animations than setTimeout.
For urgent work that must run before the next event or paint. queueMicrotask adds the callback to the microtask queue, which the event loop drains before rendering and macrotasks.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.