What Can't You Use as a Variable Name?

We've talked briefly about what makes a good variable name. We also described meaningless variable names like x as "bad" in the sense that they aren't especially clear or helpful. But they are valid. Not all variable names are.

Here are a few things to keep in mind when naming variables:

  1. Variable names are case-sensitive. myVariable is different from MyVaRiAbLe.
  2. Variable names can't contain spaces. my variable is invalid.
  3. Variable names can't start with a number. 1variable is invalid.
  4. Variable names can't contain special characters like ! or @.

Try creating a few variables with invalid names. What happens?

When you've had enough of the JavaScript engine complaining about your variable names, click the ✓ button.