(function(){
var x = 23;
return function(){
var x = x;
return x;
}
}())();
Why does it return undefined instead of 23?
Shou
there is a concept called variable hoisting.. i.e in short, just before executing the function, all variables that are declared inside function will be marked undefined. so it returns undefined.. Because of variable hoisting, you can define variable later but can use it before.. eg. function(){alert(x);var x;} will alert undefined but where as function(){alert(x);} throws error..