JavaScript Variable
Javascript uses variables to store values temporarily in internal memory. A variables values change depending on the results of an expression.Uses variables to store, retrieve, and manipulate values that appear in your code.
Declaring variables
JavaScript variables are used for storing data values.The var keyword is used for declairing javascript variable.eg:
<script>
var x = 5;
var y = 6;
var z = x + y;
</script>
JavaScript Variable Names
Naming your variable in javascript must follow some rules.They are:
- Any reserved keywords are not used for declaring javascript variables.eg: abstract,boolean,break,byte,case,catch,char,.. not using these names are not using for declaring variables.
- JavaScript variable names are case-sensitive. For example, Name and name are two different variables.
- JavaScript variable names should not start with a numeral (0-9).
JavaScript DataType
JavaScript provides different data types to hold different types of values. In JavaScript, there are primary(primitive) data types, composite(reference) data types, and special data types.
Primary(primitive) Data Types
- String:It is used for represents sequence of characters.eg:”hi”
- Number:It is used for represents numeric values. eg:100
- Boolean:It is used for represents boolean value either false or true
Composite(reference) Data Types
- Object:It is used for represents instance through which we can access members
- Array: It is used for represents group of similar values
Special Data Types
- Null: It is used for represents null i.e. no value at all
- Undefined: It is used for represents undefined value