Ben Aston
Ben Aston

Reputation: 55729

Does the following code synchronously return a resolved promise?

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

Answers (1)

Zoldszemesostoros
Zoldszemesostoros

Reputation: 397

Yes, they're completely equal. Async-await is just a syntactic sugar.

Upvotes: 2

Related Questions