(function(){
var foo;
function foo(){/* 1 */};
function foo(){/* 2 */};
})();
Scope variables are resolved after functions and unless we forget to assign a value, leaving them undefined, these variables will have a privileged reference. This means that if we declare var foo = null; exactly at the top of above example scope, the latter one will consider foo a null reference.
(function(){
alert(foo); // the function!
// function foo(){/* 2 */}
var foo = null;
alert(foo); // null
function foo(){/* 1 */};
function foo(){/* 2 */};
alert(foo); // null
})();
Code Execution
© Andrea Giammarchi