What will be the order of following code:
new Promise((resolve, reject) => {
resolve(1);
resolve(2);
reject("error");
}).then(
(value) => {
console.log(value);
},
(error) => {
console.log("error");
},
);
The code will output:
1
This is because:
resolve()
or reject()
call takes effectresolve(1)
is called first, so the subsequent resolve(2)
and reject('error')
are ignored.then()
handler receives the value from the first resolve(1)
call and logs it