created by Brian LeRoux & Andrew Lunny. sparodically uncurated by David Trejo.

2010 02 23 declaration vs initialization

    var a = 8;
    var someFunc = function(){
        var a = 8;
    someFunc(); // writes undefined

Of course, the variable is undefined because its being declared but not initialized until after the document.write in the function context which itself runs before the first declaration of a. Yowza. Cheers to Boaz, Al & Rick for this one!

Fork me on GitHub