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

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

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