JS Variables
In this tutorial, you will learn about JavaScript variables , how to declare , initialize and use them with the help of examples.
JavaScript Declare Variables
In programming, a variable is a container (storage area) to hold / store data. To declare a variable we use var keyword. For example :
JavaScript Identifiers
All JavaScript variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x, a, b and y) or more descriptive names (personName, age, sum, salary).
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter.
Names can also begin with $ and _ .
Variable Names are case sensitive (y and Y are different variables).
Reserved words (like JavaScript keywords) cannot be used as names.
JavaScript Define Variables
After the declaration, the variable has no value (technically it is undefined).
To assign a value to the variable, use the equal sign:
Run codeShare this page on :
© 2022 AnalyzeCode.com All rights reserved.