Posted By

housecor on 09/23/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

harrison3001


Javascript scope


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

  1. var jj = 0;
  2. function testFunc2() {
  3. jj = 42;
  4. //Don't declare your variables like this.
  5. //It is only an example to illustrate that variables declared anywhere in the function have function scope
  6. var jj;
  7. }
  8.  
  9. testFunc2(); alert(jj);

Report this snippet  

You need to login to post a comment.