Click here to Skip to main content
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 21:36pm
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 Sergey Alexandrovich Kryukov 853
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 166
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2014
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