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

183
Views
how do I delay the exiting from a function in javaScript?

my problem is that I need to wait a bit before returning the value. the function is returning the variable x before the var updates (or at least I think that it's the problem).

var x; //now it's undefined
  con.connect(function(err) {
    if (err) throw err;
    con.query("SELECT * FROM usrs", function (err, result) {
      if (err) throw err;
      x= result; //trying to update x
  });
});
  return x; //returns undefined(because it doesn't have enough time to change so it stays like it was at the beginning)

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!