Can someone explain me why var doesn't overwrite previous values inside for loop. I know that var overwrite values when is in function and then I should use let or anonymous function. Below is an simple example:
for (var a=0; a<10; a++) {
console.log(a);
}
Output is from 0-9. But since var has function scope, in my reasoning the variable should be overwritten and output 9 times the same number(9).