Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda