Q1.) Why I am getting undefined if i pass console.log in then block in a promise chian?
new Promise((resolve, reject) => {
console.log(4)
resolve(5)
console.log(6)
}).then(() => console.log(7))
.catch(() => console.log(8))
.then(() => console.log(9))
.catch(() => console.log(10))
.then(() => console.log(11))
.then(console.log)
.finally(() => console.log(12))
Output:
4 6 7 9 11 undefined 12
Q2.) However if I pass console.log in then block using arrow function, i get nothing as output wrt that then block.
new Promise((resolve, reject) => {
console.log(4)
resolve(5)
console.log(6)
}).then(() => console.log(7))
.catch(() => console.log(8))
.then(() => console.log(9))
.catch(() => console.log(10))
.then(() => console.log(11))
.then(()=>console.log)
.finally(() => console.log(12))
Output: 4 6 7 9 11 12
Can anyone explain this behaviour?
I am just curious to understand this behaviour of our beloved JS.