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

184
Vistas
Is there a difference between the two code codes?

First Code

console.log('Start');  // output 1
await axios({
  method: 'post',
  url: '<HTTP_URL>'
  data: <SOME_DATA>,
}).then ((response) => {
  // Do something... It could take a few seconds.
  console.log(response); // output 2
});
console.log('End');  // output 3

Second Code

console.log('Start');  // output 1
await axios({
  method: 'post',
  url: '<HTTP_URL>'
  data: <SOME_DATA>,
}).then (async (response) => {
  // Do something... It could take a few seconds.
  console.log(response); // output 2
});
console.log('End');  // output 3

Can the difference in asynchronous operation be caused by 'async' keyword of callback method?

In my test, the both source codes showed the same result.

In the second source code, I thought 'await' would guarantee only the call of the async callback. However, it actually guaranteed the complete of the async callback.

Why if they do the same thing?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The difference would be if you need to await for a certain function within the then block.

console.log('Start');  // output 1
await axios({
  method: 'post',
  url: '<HTTP_URL>'
  data: <SOME_DATA>,
}).then (async (response) => {
  // Do something... It could take a few seconds.
  await slowResponseFunction();
  console.log(response); // output 2
});
console.log('End');  // output 3
about 4 years ago · Santiago Trujillo 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