Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!