Tsallaka zuwa abun ciki
Justice Tech School

Timers and the Event Loop Order

process.nextTick runs before promises, which run before timers. setImmediate runs after the current poll phase. Understanding the order explains many surprises.

Example
setTimeout(() => console.log('timeout'), 0);
setImmediate(() => console.log('immediate'));
Promise.resolve().then(() => console.log('promise'));
process.nextTick(() => console.log('nextTick'));
console.log('sync');

Result

sync
nextTick
promise
timeout
immediate

Exercise

Run before promises.

process.(fn)

Quiz Test

What prints first?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.