Naming Variables

Variable labels should be meaningful, but you can choose almost any label you like. There are just a few rules to be aware of.

CamelCase

Labels with multiple words can be easier to read in camelCase. A camelCase label looks like sizeOfRectangle or aReallyLongLabelName. The first letter of the variable name is usually lower case, each new word starts with a capital letter. This helps you see the start of new words without using spaces, which are not allowed in variable names.

Naming Rules

There are a few rules when choosing labels:

  • Labels cannot include spaces. For example, width of rectangle would generate an error.
  • Labels cannot begin with a number. 4sides and 2morrow will generate errors.
  • Be very careful with spelling. If labels are not spelled exactly the same way, the computer will not realize that they refer to the same variable.
  • Labels are case-sensitive. size is not the same as Size or SIZE.