I have a simple code
async function foo() {
const b = bar()
return 2 + b
}
async function bar() {
return 2
}
(async() => {
console.log(typeof foo())
})()
and it logs object
. Not NaN
. How does it happen that number + object
-> object
?
From what I remember from +
spec if one of the operands is a primitive and second is an object then object should be converted to primitive. In this case with .valueOf()
method
It think it's because
async
functions are not resolved yet in your case, becaue there is noawait
. So you are getting promise objects instead of your result.see these cases: