I'm new in javascript world. Reading about the variables scope and I think I got the idea behind. I did some experiments and I'm having a situation here which gives me unexpected results. Here's what I mean
var x = 0;
function set(){
x++;
}
set();
console.log(x) // 1
At this point of the script the value of x is 1 as expected
total = 0;
var id = setInterval(function(){
total++;
}, 10);
console.log(total); // 0
At this point of the script the value of total is always 0. I've checked and I'm sure the value of total is incremenated. So what's wrong with the second example and why the value of global variable total is not changed?