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

151
Views
Getting returned function value in javascript

Im trying to find the value of sendback, however when I console.log(findavailbase()) it is undefined. I know im missing something obvious but Ive been looking for a good ten minutes and I cant find the issue. here is the code:

function findavailbase() {
  var sql1 = `select capacitylimit,currentload,baseid  from bases `;

  con.query(sql1, function (err, result) {
    if (err) throw err;
    for (let i = 0; i < result.length; i++) {
      if (result[i].capacitylimit > result[i].currentload) {
        const sendback = result[i].baseid
        return sendback

      }
    }

  });

}


console.log(findavailbase())

Any help would be appreciated.

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!