I am writing mysql query and kept those records in variable, My requirement is to get access that variable in anywhere so declared it outside of route,but it is showing error like : SyntaxError: Missing initializer in const declaration
const totalQuery = "select name from users";
const totalRecords;
dbConn.query(totalQuery,function(err,rows) {
totalRecords = rows.length
})
console.log('::'+ totalRecords);
process.exit();
Error:
SyntaxError: Missing initializer in const declaration
In javascript, you can't assign value to 'const' later after it's declaration. You're bound to assign the value to const on the declaration line.
If you really need to declare the value some where later, then better go with 'let'
Make it let instead of constas you are re-assigning the totalRecords variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With