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

440
Views
JS - Function returning undefined object while using axios. Log before return is an object, log after return is undefined

So I've got two functions. The first function calls the second. The console.log(listDogs) appears to show an object. the console.log(listDogs2) shows as undefined. The idea outcome is that the return from the function is the same as before.

async function listDogs() {
    let listDogs2 = await getListDogs();
    console.log(listDogs2);
}

async function getListDogs(){
    await axios.get(`https://dog.ceo/api/breeds/list/all`)
    .then(response => {
        let listDogs = response.data.message;
        console.log(listDogs);
        return listDogs;
    }).catch((err) => {
        console.log(err);
    });
}

Console Output
line 31 is console.log(listDogs);
line 7 is console.log(listDogs2);

Console output

Any help appreciated. Either a solution, or a pointer about where to read. Have done quite abit of searching and cannot get my head round it. Thanks in advance.

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