Reputation: 55729
Does the following code synchronously return a resolved promise with a value of 1
?
async function foo() {
return 1
}
const p = foo()
console.log(p)
Is it semantically equivalent to the following?
function foo() {
return Promise.resolve(1)
}
const p = foo()
console.log(p)
Upvotes: 1
Views: 44
Reputation: 397
Yes, they're completely equal. Async-await is just a syntactic sugar.
Upvotes: 2