Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why use "var" to create variables 1

Status
Not open for further replies.

firegambler

Technical User
Sep 25, 2002
455
AT
Hi folks,

I am wondering why many of you use "var" to create a variable if it is possible to create variables by just using a name and giving it a value.

Could you please explain to me the advantage of using "var"?

Thanks in advance!

regards

tektips.gif
 
i use var when i want to restrict the scope of a variable

for(var i = 0)

means that i is only defined within the for loop and cant effect any other i outside the for loop

same with functions.....sometimes you only want a variable yo have a value within a function so you use var. sometimes you want a varaible to be available throughout the timeline in which you probably wouldnt use var

clear as mud?

 
Yep! :) Clear as mud :-D
Thanks for the explanation!
Is there any other reason for using "var" too or is the only purpose to use it the restriction of the area of variable validity?

regards

tektips.gif
 
its just to restrict the availability...buts its good practise especially if you are writing fairly long and involved programs to restrict availabilty and avoid unforeseen knock on effects
 
It also helps the movie to run (very, very) marginally faster as the Player knows where to look for the variable value in advance.

Apparently.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top