我正在编写 mysql 查询并将这些记录保存在变量中,我的要求是在任何地方访问该变量,因此在路由之外声明它,但它显示错误,例如:SyntaxError:const 声明中缺少初始化程序
const totalQuery = "select name from users";
const totalRecords;
dbConn.query(totalQuery,function(err,rows) {
totalRecords = rows.length
})
console.log('::'+ totalRecords);
process.exit();
Run Code Online (Sandbox Code Playgroud)
错误:
SyntaxError: Missing initializer in const declaration
Run Code Online (Sandbox Code Playgroud)