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

140
Vistas
Why does this code block log to the console in an unexpected order?

I'm extremely confused why the following code returns what it does when I write it using both promise chaining and async/await syntax:

function log() {
  console.log("Hello from inside second await")
}

async function test() {
  await console.log("Hello from first await");
  await setTimeout(log, 1000);
  await console.log("Hello from third await");
}

test();
console.log('Where does this occur?')

I thought the await keyword made the code asynchronous. Why is the first await printing to the console instantly ahead of the console.log in the main thread? Additionally, why is the second await occurring after the third? Isn't the purpose of await to make sure that important data for future functions exists before they're executed? This makes no sense to me, help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The async function means it will be to executed somtime. More from javascript async functions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

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