My goal is to set someVar
to 1 if my SQL query finds a result.
The problem is that the assignment is local and when I try a console.log(someVar)
, the result is 1 inside the block, but 0 outside it. Is there a way to export the value outside it?
let someVar = 0;
con.query(`SOME SQL QUERY`, (error, rows) => {
if (error) throw error
if (rows.length > 0) {
someVar = 1;
//console.log(someVar) -> The result is 1
}
});
con.end();
//console.log(someVar) -> The result is 0
if (someVar === 0) {
// Some code
}