Javascript: Variables Naming

Variable names can start with the following characters:

  • Upper- or lowercase letter
  • An underscore (_)
  • A dollar sign ($)
 Although you can use an underscore or dollar sign to start a variable, it’s best to begin with a letter. Unexpected characters can often cause your code to look confusing and difficult to read, especially if you are new to JavaScript coding.

After the first character, you can use any letter or number in your variable name, and it can be any length. JavaScript variables cannot contain spaces, mathematical operators, or punctuation (other than the underscore).

Always remember that JavaScript is case-sensitive. A variable named myname is not the same variable as Myname or myName.

Variable names are actually identifiers; the best thing you can do is to name a variable something precise and relevant. This naming convention may sometimes result in very long names, but as a rule, a longer name that accurately represents the variable is more useful than a shorter name that is vague.

No comments:

Post a Comment