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

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

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 Relatório

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 Relatório

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 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