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

442
Visualizações
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
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