I have code in which i have two variable with same name. first variable is global and other one is inside the function. as per specification all global variables are attached to the window object but when i was trying to access global variable inside function it is showing undefined in jsfiddle but same code is working fine in console.
var myVar='10';
function check() {
alert('Local : ' + myVar+ ', Global : ' + window.myVar); //window.myVar is undefined in jsfiddle
var myVar;
}
check();
What is the reason of this unexpected behavior?
Here is JSFiddle