I executed following code with Node.js v10.15.0
Promise.resolve() .then(() => console.log('A')) .then(() => console.log('B')) .then(() => console.log('C')) setImmediate(() => console.log('IMMEDIATE')) Promise.resolve() .then(() => console.log('D')) .then(() => console.log('E')) .then(() => console.log('F')) As there is no asynchronous code involved in the fullfilled functions i expected following output
A B C D E F IMMEDIATE but i got...
A D B E C F IMMEDIATE As far as i understand the situation, the setImmediate() call shows us, that none console.log() call gets deffered to the next Event Loop iteration. But, why is the order of console.log() calls mixed up?