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

225
Views
What is happening if Async Func returns a promise?

And also, if Async function return a promise, it doesnt return the same promise, but that promise is somehow changed so its not equals itself. And is there a difference if I would return a promise synchronously without any awaits, or with them?

let promise = new Promise(resolve => resolve());

async function test() {
  
  return promise;

}

console.log(promise === test()); // false

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

0

The async keyword always makes a function create and return a new promise which will only get resolved after all the work (asynchronous and synchronous) of that function is complete.

In other languages like C# you would have to return await promise, or the calling code would have to await await test(), since return promise would cause the async function to return a promise with another promise inside.

In JavaScript, when you return a promise from within an async function, the promise that actually gets returned from your function knows to effectively await that other promise and resolve with the value (if any) that it returns. This behavior is merely a convenience, because there are very, very few use cases for actually returning nested promises, while it's highly likely for someone to make the mistake of forgetting to await a promise before returning it. But the async function is still returning a new promise, not the one provided by the return statement.

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!