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

194
Views
Javascript - Returning data from const-declared arrow function

I've a function that makes a simple pgsql query which I'd like returned to the const variable it's declared in, so I can access it in other parts of the code.

const Id = client.query(idQuery, (err, result) => {
    if(err) {
        console.log(err);
    }
    const Data = result.rows;
    if(Data == undefined) {
        console.log("Running query ...");
    } else {
        console.log("Done.");
    }
    return Data;
})

Yet, if I try to assign its value like so: const testVar = Id, the value is always undefined. The same is true if I console.log(Id). There's probably something very simple that I'm glancing over, but I've declared other functions similarly with successful output.

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!