What Are JavaScript variables?

Identifiers

We can give our variables almost any identifier we want. There are some rules though; the most important rules are listed below.

  • Only use the Latin characters (a-z, A-Z, 0-9) and the underscore character
    • JavaScript does technically support UTF8 identifiers, but they can sometimes cause issues
  • Identifiers cannot start with numbers
    • The interpreter will give us an error if we do this
  • Do not use any of the reserved JavaScript words, which includes the words that define the syntax of JavaScript language

Case sensitive

Identifiers in JavaScript are case sensitive, which means that firstName is not the same as firstname.

Identifier examples

Examples of good identifiers

  • id
  • lessons
  • audio2
  • audio2

Examples of bad identifiers

  • 2names
    • starts with number
  • const
    • language keyword
  • sldfjiewofjxncv
    • technically valid, but does not tell the reader anything useful
  • videooutputsignalfromtheclosetinnarnia
    • technically valid, but too long and hard to read