const p1 = new Promise((_, reject) => {
reject(1);
}).then((r)=>console.log(r)).catch((r)=>console.log(r));
const p2 = new Promise((resolve, _) => {
resolve(10);
}).then((r)=>console.log(r)).catch((r)=>console.log(r));
// output -> 10, 1
Shouldn’t the output be 1, 10.Because the catch block of p1 is added to the microtask queue before then block of p2?
Below example gives expected output of 1,10
const p1 = new Promise((_, reject) => {
reject(1);
}).catch((r)=>console.log(r))
const p2 = new Promise((resolve, _) => {
resolve(10);
}).then((r)=>console.log(r)).catch((r)=>console.log(r));