Consider the following code (http://jsbin.com/vewot):
var shouldDefine = false;
if(shouldDefine) {
function something() {
var a = 1;
}
}
alert(typeof something);
What would you expect the alert to show? For me, I would expect it to say "undefined", because the if block should not be run, since shouldDefine = false. And in Firefox, that is what happens.
But in Chrome and IE9, it says 'function'! Is this a browser bug or is this legitimate JavaScript behavior?