When i execute the following script the alert statement is printing the function why is it so?
What happens in the execution context? Why the variable basicPattern’s undefined value is not printing?
function basicPattern(){
var o = 5;
return o;
}
var basicPattern;
console.log(basicPattern);
Evaluates same as this (IE bugs disregarded):
Since
basicPatternwas already declared, declaring it again won’t have any effect since declarationsare hoisted and merged. If you had assignment to
5it would go like this:Read more about hoisting: http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting