Facebook Pixel

What is the difference between setTimeout, requestAnimationFrame, and queueMicrotask?

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).

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in setTimeout vs requestAnimationFrame vs queueMicrotask in JavaScript

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.

Sync code runs first. Then microtasks (queueMicrotask, Promise.then). Then requestAnimationFrame (before the next paint). Then setTimeout (macrotask, after rendering).

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.