Possible Duplicate:
variable hoisting
    var a = "global";
    //version 1
    function changeGlobal(){
        alert(a); //why is 'a' undefined here?
        if(a){ 
        var a = "local";
        alert(a);
        }
    }
    //version 2
    function changeGlobal(){
        alert(a); //why is 'a' 'global' here? what diff does 'var a="local"' make?
        if(a){ 
        //var a = "local";
        alert(a);
        }
    }
    changeGlobal();
Question are inline. Help me understand variable scoping.
 
     
     
     
    