easierbycode
3/1/2012 - 10:11 PM

declaration vs initialization

declaration vs initialization

// 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.

    var a = 8;
    var someFunc = function(){
        document.write(a);
        var a = 8;
    };
    someFunc(); // writes undefined