In the code snippet below both the setTimeout and reject get executed asynchronous. My impression is that setTimeout pushes to the even queue, then reject pushes to the event queue. Then the setTimeout fetes and executes immediately, the the reject. All that means 6 to be logged first then 3, however o my shock the console logs:
3
6
why is that? Why reject before the setTimeout?
let promise = new Promise(
function (resolve, reject) {
setTimeout(() => {
console.log(" 6 ");
}, 0);
reject(" 3 ");
resolve(" 4 ");
}
);
promise.then(
function (st) {
console.log(st);
},
function (st) {
console.log(st)
}
);