I'm a beginner in JS. Can someone please explain why the console prints out 3, 2, 1 instead of 1, 2, 3? Even if I change the order of the lines of code, the result will always be 3, 2, 1. I don't understand why, please help!
setTimeout(function timeout() {
console.log('1');
}, 0);
Promise.resolve('2').then(console.log);
console.log(3);
Here I changed the order to 2, 1, 3, but the result is still 3, 2, 1
Promise.resolve('2').then(console.log);
setTimeout(function timeout() {
console.log('1');
}, 0);
console.log(3);