Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda