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

180
Visualizações
Console.log() and return are giving me different answers to same variable. javascript

I am writing an app to track crypto prices to get some work on some of the new coding practices I have been learning. I have ran into a problem where in one of my functions I console.log() a variable and get the answer I need, but when I return that to be set to another variable to use I get a different answer.

I am looking to use an API to scrape prices and other info for crypto and then pass it into a node route to use on the page through ejs. Here is where I am having trouble;

async function axiosTest() {
  const response = await axios.get(
    'https://api.coingecko.com/api/v3/coins/markets?vs_currency=USD&ids=bitcoin&order=market_cap_desc&per_page=100&page=1&sparkline=false&price_change_percentage=24hr%2C7d'
  );
  return response.data;
}

const BTCdata = axiosTest().then((data) => {
  console.log('in axios test', data[0]);
  return data[0];
});

app.get('/', (req, res) => {
  console.log('in /GET', BTCdata);
  res.render('home');
});
in 'const BTCdata...' when I console.log data[0] I get what I need. then I return that to be saved as BTCdata(right?) it comes out different. It is coming out in as a nested object when I return it. I am not sure how to use the data in the nested object. in the console.log I could type 'data[0].name' and get the correct information, which is what I'm attempting to do. When I console log the data in BTCdata and in my /GET they are different.

I'm looking to get this data from the API so I can pass it through to my home page template and render the information on my page.

THANK YOU ALL for always being so helpful.

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