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:
- String variables
- Date variables
- Numeric variables
var str="This is a string"
var dt=new Date(2005,11,29)
Rating:
Was this information helpful?
Other articles
- What is auth_user property of the request object?
- What is the href property?
- How to create an external script file?
- How are cookie files stored in different browsers?
- How to use the open method?
