Guess the output!!
console.log('1');
setImmediate(() => {
console.log('3');
});
setTimeout(() => {
console.log('4');
}, 0);
process.nextTick(() => {
console.log('2');
});
OUTPUT:
1
2
4
3
Guess How?? (Try to run the code here.)
Output depends on the priorities of different queues involves in the execution.
Priority of [ process.nextTick() > Timer Queue (setTimeout) > Check Queue (setImmediate) ]
Top comments (0)