Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Does "return await" makes any difference?

Is there any difference between

const foo = async () => {
  // some other code that uses await
  return await bar()
}

and

const foo = async () => {
  // some other code that uses await
  return bar()
}

Where bar is a function that returns a promise.

Is the await redundant or does it make any difference?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

It is redundant.

It extracts the value from the promise returned by bar, and then resolves the promise returned by foo with it.

If you return bar's promise directly, then the promise returned by foo adopts it to the same effect.

about 4 years ago · Juan Pablo Isaza Report

0

If the Promise is rejected, the error would be thrown in different places, in the two example you wrote.

In the first, a rejected error would happen inside foo.

In the second, a rejected error would happen to the function that called foo

about 4 years ago · Juan Pablo Isaza Report

0

Yes.

If the function bar() returns a Promise, in the second case foo will return a pending Promise (a Promise that has not yet resolved). In the first case, foo will return the data the Promise resolved with after waiting for the Promise to resolve

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!