Click here to Skip to main content
12,066,626 members (55,983 online)
Rate this:
 
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
Top Experts
Last 24hrsThis month


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