| To var or Not to var |
|
|
|
| Sunday, 19 March 2006 | ||||||||
Page 4 of 6
How var Affects Variable ScopeWe're almost done. Just one more piece to the puzzle. Just as declaring a variable in a execution context (inside a function, so it is local, or outside all functions so it is global), the var keyword can also affect whether a variable is local or global. If you use the var keyword, you are writing a var statement, such as var x = 10. Using a var statement declares that the variable should be local to the current execution context. Not using a var statement, however, declares that the variable should be global. So if you don't use var, no matter where you declare the varible, it will have a global scope. Here's an example. |
||||||||
| Last Updated ( Sunday, 19 March 2006 ) | ||||||||
| < Prev | Next > |
|---|










