Skip to content Skip to sidebar Skip to footer

Firebug Console Not Doing Hoisting

console.log(a()); function a(){ console.log('hello'); } From above code, i will expect 'hello' (and some undefineds) to be logged on console. But firebug gives ReferenceError:

Solution 1:

The reason for the issue is that

functions do not hoist when declared inside a child block.

by MDN (Much covered here is not standard ECMAScript).

Compare the following snippets:

alert(c());
functionc(){return42;}

and

{
    alert(c());
    functionc(){return42;}}

The first one will alert 42, whereas the second one will throw ReferenceError.

And here is the code that gets executed when you are playing with Firebug: Firebug's tooltip

data;
with(_FirebugCommandLine){ // >> block beginsconsole.log(a());
    functiona(){
        console.log("hello");
    }
} // << block ends

Update The behavior observed seems to be a glitch in Firefox javascript engine because it is not observed in chrome and IE9, see this fiddle.

Post a Comment for "Firebug Console Not Doing Hoisting"