Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda