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

153
Views
A variable inside async function derived from a promise has different value when returned to global scope

I do not understand why the query variable has a value inside async function that changes when returned and declared in the global environment. I want to return the value from my database to a global variable outside of the async function. What is the logically reason this happens. How do I extract the integer value from the Promise {1}.

async function glob(){

    var result = await knex.raw('select max(glob) from or');
    let query = await result.rows[0].max ;
    console.log(query);
    return query ;
   
}

let go = glob();

setTimeout(()=>{console.log(go)},1000);
setTimeout(()=>{console.log(go == 1)},1000);

The console returns.

1
Promise { 1 }
false

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!