Okey so I think this has to do something with scoping, but im fairly new to javascript.Inside the function of the database query totalSum has an value, but when I ask for the value outside the function it says its 0. Could someone help me out?
socket.on('sumDoughnut', function(data){
var totalSum = 0;
mysqlConnection.query('SELECT SUM(value) AS Total FROM doughnut', function(err, row, results){
if(err) {io.to(socket.id).emit('err_client', { code : 22 });console.log("MySQL error: " + err);if(err.code === 'PROTOCOL_CONNECTION_LOST'){handleDisconnect();}}
totalSum = row[0].Total;
console.log("here it is " + totalSum);
});
console.log(totalSum + " totalSum")
}