Variables are used to store values (name = "John") or expressions (sum = x + y). Before using a variable, you first need to declare it. You have to use the keyword var to declare a variable like this:
1
| var name; |
You can assign a value to the variable either while declaring the variable or after declaring the variable.
1
| var name = "John" ; |
OR
1
2
3
| var name; name = "John" ; |
Naming Variables
Though you can name the variables as you like, it is a good programming practice to give descriptive and meaningful names to the variables. Moreover, variable names should start with a letter and they are case sensitive. Hence the variables studentname and studentName are different because the letter n in name is different (n and N).
Try this yourself: