Remember that storing information in variables is like putting data into labeled boxes?
For example:
let score = 100;
Engagement Message
Can you tell me what value is stored in score
?
Now, let's talk about the names we give our variables. Just like you can't label a real box with anything (maybe not symbols or blank spaces), there are rules for naming variables in JavaScript.
Variable names can contain letters (a-z, A-Z), numbers (0-9), the underscore character (_
), or the dollar sign ($
).
Engagement Message
Make sense so far?
However, there's a catch with numbers: a variable name cannot start with a number.
So, player1
is a valid name, but 1stPlayer
is not.
Engagement Message
Do you think we can make a variable named 0Day
?
Another important rule: variable names cannot contain spaces. If you want to represent a multi-word concept, use camelCase like highScore
(which is common in JavaScript).
For example, highScore
is good, but is not.
