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

133
Visualizações
what fetch return when "then" statement is used and when without "then"?
 const res3 = await fetch(url2, {
      method: "GET",
      header: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
    })
    .then((response) => response.json())
    .then((data) => {
       console.log("Success:", data);
     })
    .catch((err) => console.log("thown error-->" + err));
    
    console.log(res3);
     const response=await res3.json() //erroneous line
    console.log(response);
    

here res3 = undefined is printed

and when the below code is executed

 const res3 = await fetch(url2, {
          method: "GET",
          header: {
            Accept: "application/json",
            "Content-Type": "application/json",
          },
        });
        
    const response=await res3.json()
    console.log(response);

response = [object , Object] is printed on console

and when try to access the response as response.obj where the backend sends back the response as: res.json({ obj:data, msg:"Success" })

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