Take a example of this one:
var is_android = true;
if (is_android) {
function foo() {
alert('I am Android');
}
} else {
function foo() {
alert('I am NOT Android');
}
}
foo();
It will be interpreted as
function foo() {
alert('I am Android');
}
function foo() {
alert('I am NOT Android');
}
var is_android;
is_android = true;
if (is_android) {
} else {
}
foo();
It will alert "I am NOT Android"; Looks like the second foo definition overwrites the first one.
It treats function definitions as declarations, my question is , when will this happen or is this always the case? How to make javascript treat something as a function definition?
Thanks.