Can someone please tell me why the last logging of 'x' equals 0 and not 1. I thought because it's declared outside of a function it has global scope and then in the function it's value is set to 1 and that value would remain as it's a global? I know the first 'x' value inside the function is a global as any variable declared without the var keyword becomes a property of the window object. Many thanks
var x = 0; //global variable
function y(){
x = 1;
log("1. %n ", x);//1. 1
var x = 2;
log("2. %n ", x);//2. 2
}
y();
log("3. %n ", x);//3. 0