View Full Version : what's var?
gpopguru
04-08-2004, 09:55 PM
This may sound stupid, but what is the difference between these two scripts?
var x = 5
alert(x)
and
x = 5
alert(x)
they'll do the same thing, so when would I ever have to use "var?" :confused:
When there is no , it is "universal" meaning it can be accessed from another script. If it has [I]var, then it only works for the script you are in, so you can use the same variable label in different ways.
Choopernickel
04-08-2004, 10:04 PM
Worthy of note: with Mozilla's script engine in Strict mode, declaring a variable without var in any scope (not as a property of an object, mind) will throw a "Warning."
Roy Sinclair
04-08-2004, 10:12 PM
Here's another thread on this same subject: http://www.codingforums.com/showthread.php?t=21356
gpopguru
04-08-2004, 10:24 PM
Ooh! thanks! I didn't know that Lol.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.