/ Published in: JavaScript
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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);