I'm trying to update the value of start
inside an anonymous function contained within the block but this does not seem to be happening.
When I declare a variable with let
, I imagined that this variable would be block scoped and it's value could be updated by anonymous functions within the block.
What am I doing wrong?
function getStartTime(Id) {
let start = '';
let bQuery = "select StartTime from database.table where Id=?";
dbService.executeDQuery(bQuery, Id, function (error, rs_bs) {
if (error) {
next(error);
return;
}
start = JSON.stringify(rs_bs[0]["StartTime"]);
console.log("start in = " + start); //shows the correct value
});
console.log("start out = " + start); //this is empty
return start; //nothing returned
}