var foo = function(){ return 1; };
if (true) {
function foo(){ return 2; }
}
foo(); // 1 in Chrome // 2 in FF
//I just want to be sure, is FF 4 not \"s
fiddle. This is Undefined Behaviour. It's a mess.
How firefox interprets it is handled by the other answers
How chrome interprets it
var foo = function() { return 1 };
if (true) {
function foo() {
return 2;
}
}
console.log(foo());
What's acctually happening is function foo is being declared then overwritten with a local variable foo immediately.
This gets translated into
function foo() {
return 2;
}
var foo;
foo = function() { return 1 };
if (true) { }
console.log(foo());