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

120
Views
axios function is running after other lines of code

My Code:

var latlng = {lat: 7, lng: 7};

function findLatLng() {
    var testLocation = '350 Victoria St, Toronto';

    axios.get('https://maps.googleapis.com/maps/api/geocode/json', {
        params: {
            address: testLocation,
            key: 'MY KEY',
        }
    })
    .then(function(response) {
        console.log(response.data.results[0].geometry.location);
        return response.data.results[0].geometry.location;
    })
    .catch(function(error) {
        console.log(error);
    });
}

latlng = findLatLng();
console.log(latlng);

In the console, latlng is logged as undefined, but the console.log(response.data.results[0].geometry.location) is logged with the proper value;
it is also logged afterwards even though it should have executed first.

I think this is because the code continues despite findLatLng() not being done with the request but I'm not sure. When I check the value of latlng in the console afterwards, it becomes the proper value.

What is the issue and how do I fix this please?

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!