Return to Snippet

Revision: 32366
at September 23, 2010 05:01 by housecor


Initial Code
var jj = 0;
function testFunc2() {
    jj = 42;
    //Don't declare your variables like this.
    //It is only an example to illustrate that variables declared anywhere in the function have function scope
    var jj;
}

testFunc2(); alert(jj);

Initial URL


Initial Description
There are two scopes in JavaScript: global and function. If you don\'t declare a variable (using var), it assumes global. \r\n\r\nVariables declared in functions have function scope.

Initial Title
Javascript scope

Initial Tags


Initial Language
JavaScript