Click here to Skip to main content
11,495,945 members (63,478 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
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 15-Nov-12 22:36pm
mhd.sbt1.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 CHill60 318
2 Sascha Lefèvre 235
3 RyanDev 230
4 _Asif_ 155
0 Sergey Alexandrovich Kryukov 10,372
1 OriginalGriff 8,871
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100