How to declare a variable in JavaScript?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

How to declare a variable in JavaScript?

Rating:

Variables are identifiers that are declared to store data in memory temporarily and retrieve them when necessary. In JavaScript, variables are declared by using the var keyword. Different types of variables can be declared by using the var keyword. Variables can be declared inside or outside of the function. When a variable is declared inside the function, it is called a local variable. When it is declared outside the function, it is called a global variable. The life of a global variable ends when the page unloads, while the life of a local variable ends with the end of the execution of the function in which it is declared.

Variables can be declared as follows:

  1. String variables


  2. var str=new String("This is a string")
    var str="This is a string"


  3. Date variables


  4. var dt=new Date()
    var dt=new Date(2005,11,29)


  5. Numeric variables


  6. var num=22


Rating:



Other articles

Click here to Article home

MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW Certification: CIW foundation, CIW Professional, Site Designer    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.
 
HACKER SAFE certified sites prevent over 99.9% of hacker crime.