JavaScript Identifiers

Identifiers are names. In JavaScript, identifiers are used to name variables (and keywords, and functions, and labels). The rules for legal names are much the same in most programming languages. In JavaScript, the first character must be a letter, an underscore ( _ ), or a dollar sign ($). Subsequent characters may be letters, digits, underscores, or dollar signs.

Numbers are not allowed as the first character. This way JavaScript can easily distinguish identifiers from numbers.

All JavaScript identifiers are case sensitive. The variables lastName and lastname, are two different variables. For example, in this script, the output value is Peterson:
    <script>
        var lastName = "Doe";
        var lastname = "Peterson";
        document.getElementById("demo").innerHTML = lastname;
    </script>

While in this script, the output value would be Doe:
    <script>
        var lastName = "Doe";
        var lastname = "Peterson";
        document.getElementById("demo").innerHTML = lastName;
    </script>

JavaScript does not interpret VAR or Var as the keyword var.

Back Table of Contents Next