- Variable is like an empty box that can be used to store information. You can place anything inside the box.
- It’s a temporary place to store values.
- Variables are pieces of memory allocated to store information.
- Variable values can be used by calling the name of variable.
var NAME_of_Array = VALUE;
var myname = "Shahid"
- In above example var is used to create a variable.
- myname is the name we assigned to our variable
- Shahid is the value we saved in our variable
- on this HTML page we can used document.write followed by the name of variable and it will show the value of variable.
Rules for Naming Variable
- Variable names are case sensitive
- Variable names cannot start with numbers
- Variable names cannot contain spaces
- Variable names can contain letters, numbers, $, _