I'm trying to get my head around the Promise API, and struggling.
This is what I've tried so far:
const myPromise = () => {
return new Promise( (resolve, reject) => {
var name = 'John'
if (name === 'John') {
resolve(name)
}
else reject('Anonymous')
})
}
Then when I console.log(myPromise())
, I get...
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: "John"}
I would expect to get John
back from this. As it stands, I don't know how to handle the data. Can anyone point out where I'm going wrong?