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

331
Visualizações
JS Why does my async function return undefined?

I'm beginning to understand async / await but I haven't figured it out yet. I really hope you can help me!

async function test1() {
  const fetchPromise = await fetch("https://www.instagram.com/boarirkeerd/?__a=1", {})
  .then(response => response.json())
  .then(response => {
    console.log(response["graphql"]['user']['id']); /* returns 43000480694 */
    return response["graphql"]['user']['id']; /* returns undefined */
  });};

if (await test1 == "43000480694") {console.log("YES");}
else {console.log('NO');} /* returns NO */
test1(); /* undefined */

The JS console shows: NO Promise 43000480694

Why is it in that order and why does the function return undefined? It should be: YES Promise 43000480694

Thanks a lot for your help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. For a function to return something, it must at least have the return keyword.
  2. To reference a function, use test1, to call a function, use test1(). The () are required.
about 4 years ago · Juan Pablo Isaza 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