Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!