This is an Extension to the Question. I have tried below code to understand JavaScript scope
var a = function(){
var aa = 10;
var x = 13;
b = function(){ c = function(){ alert(aa); }; };
};
a();
b();
c();
alert(typeof x); // Undefined
alert(x); // Returned me 13.
My query is I have declared variable with var inside a global function. As per my understanding x should be local. But it is not acting in that way. Someone please clear my doubt... Please check this fiddle.
xis scoped to the function assigned toa. That lastalertnever actually appears - you get a SyntaxError becausexis not defined.xglobals.aainside the function assigned toc.