Why do async turn a return value in to "[object Promise]
"
This is the code that I would like to work....
function foo() {
let res = bar("HELLO")
console.log(res)
}
async function bar (text) {
text = text + await getData();
return (text)
}
function getData () {
return new Promise((resolve, reject) => {
// Do a lot of stuff to find myResult
resolve(myResult)
})
}
So my question is this... how come this returns HELLO
function foo() {
let res = bar("HELLO")
console.log(res)
}
function bar (text) {
return (text)
}
and this returns [object Promise]
function foo() {
let res = bar("HELLO")
console.log(res)
}
async function bar (text) {
return (text)
}
How do I get the async function to return the text?