Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every buddy
im new in java script and a want to know that var keyword in javascript use for what?
is using for define variable or scope concept?please give me an example .
thanks
Posted

It defines a variable, which effectively defines it's scope as the current block.

If you use it, then it always creates a new variable with the given name, if you don't, then it looks back up the current scope(s) until it finds a variable with that name already and uses that instead. Or creates a new variable if it doesn't find one.

I would recommend that you use var whenever you can, as it prevents mistakes later if you didn't mean to use a global variable of the same name in two different functions!
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900