Question #201

Author: admin
tags: Node.js  
setTimeout(() => { console.log(1); });
setImmediate(() => { console.log(2); });
console.log(3);
In what order will the numbers be printed after running the code in NodeJS?
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
The timers phase is the first phase of the NodeJS Event Loop cycle.
But the decision to add to this queue is made by the poll phase.
After the poll phase is completed, the check phase is executed, in which the callbacks from setImmediate are executed.
For this reason, the callback from setTimeout with zero delay is executed in the next tick of the Event Loop cycle.
Rate the difficulty of the question:
easyhard