For example, you could prompt your website users for their first name. When they enter their first name you could store it in a variable called say, firstName.
Now that you have the user's first name assigned to a variable, you could do all sorts of things with it like display a personalized welcome message back to the user for example. By using a variable to store the user's first name, you can write one piece of code for all your users.
First, you need to declare your variables. You do this using the
var keyword. You can declare one variable at a time or more than one. You can also assign values to the variables at the time you declare them.
body element. You would also use a function for this type of thing.
- Can contain any letter of the alphabet, digits 0-9, and the underscore character.
- No spaces.
- No punctuation characters (eg comma, full stop, etc).
- The first character of a variable name cannot be a digit.