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

139
Views
Function change variable, logs undefined

I want this code to set the variable temperature to the temperature. I'm using a library (https://www.npmjs.com/package/openweather-apis)

var temperature;
await weather.getTemperature(async function(err, temp){
    console.log(temp)//logs 74.5
    temperature = temp
 });
console.log(temperature)//logs undefined

How could I have temperature (out of the function) equal to temp (in the function). Outside the function it logs undefined, inside it logs the correct temperature.

Any help would be great!

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!