If you use a variable for the first time in a function without declaring it with var, then it is a global variable, and can be manipulated in other functions. Another option is to declare it outside all functions and either assign no value to it, or assign null to it.
Lee is right.
Any variables you declare before functions are considered global. var doofy="";
Any reference to the variable doofy in or out functions refers to the SAME doofy.
I don't know, however, if, when you declare a var doofy in a function after that, it makes a local doofy (though I'm pretty sure it is in C and its variations).
Was that English? lol
If you use var to declare a variable in a function, then it's a local variable. If you don't use var, then the variable is global.
Any variable declared locally in a function is a local variable, and you won't be able to access the global variable when there's a local one with the same name. Learned this by experience when I forgot to use var one time in a function, and what was supposed to be a local variable affected a global one. Using var fixed the problem with no other changes.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.