I want to access k and error value inside and outside a function.
I had initialized the value for k as 0 and error as an empty string. But the console.log("executed")
is printed.
var k = 0;
var error = "";
const { teamname, event_name, inputcount, name, roll } = req.body;
function check1(teamname, event_name, callback) {
Register.find({ teamname: teamname, eventname: event_name }, (err, docs) => {
callback(docs.length)
});
}
check1(teamname, event_name, function (e) {
if (e != 0) {
console.log("executed");
k = 1
}
});
console.log(k) // 0
console.log(error) // undefined