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

133
Vistas
an example of async/await in javascript

I am studying async and await in javascript, and a little bit confused about the execution order of the following function I wrote when I play around async and await:

const promiseA = new Promise((resolutionFunc, rejectionFunc) => {
  setTimeout(() => resolutionFunc(666), 5000);
});

const test = async () => {
  await promiseA.then((val) =>
    console.log("asynchronous logging has val:", val)
  );
};

const testTwo = () => {
  test();
  console.log("immediate logging");
};

testTwo();

my understand is that in function <testTwo()>, <test()> execute first, it's been called & executed, <test()> is an async function, and I have put the await in front of the promise.

why this console.log("immediate logging"); line of code get executed first?

on the other hand, if I wrote <testTwo()> like following:

const testTwo = async () => {
  await test();
  console.log("immediate logging");
};

everything is fine

about 4 years ago · Juan Pablo Isaza
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