How to create identifiers
Variables, functions, objects, properties, methods, and events must all have names so you can refer to them in your JavaScript code. An identifier is the name given to one of these components.
Figure 2-6 shows the rules for creating identifiers in JavaScript. Besides the first four rules, you can't use any of the JavaScript reserved words (also known as keywords) as an identifier. These are words that are reserved for use within the JavaScript language. You should also avoid using any of the JavaScript global properties or methods as identifiers. Although you can sometimes get away with this, it will lead to problems in some applications.
Besides the rules, you should give your identifiers meaningful names. That means that it should be easy to tell what an identifier refers to and easy to remember how to spell the name. To create names like that, you should avoid abbreviations. If, for example, you abbreviate the name for monthly investment as mon_inv, it will be hard to tell what it refers to and hard to remember how you spelled it. But if you spell it out as monthly_investment, both problems are solved.
Similarly, you should avoid abbreviations that are specific to one industry or field of study unless you are sure the abbreviation will be widely understood. For example, mpg is a common abbreviation for miles per gallon, but cpm could stand for any number of things and should be spelled out.
To create an identifier that has more than one word in it, most JavaScript programmers use a convention called camel casing. With this convention, the first letter of each word is uppercase except for the first word. For example, monthlyInvestment and taxRate are identifiers that use camel casing.
The alternative is to use underscore characters to separate the words in an identifier. For example, monthly_investment and tax_rate use this convention. If the standards in your shop specifies one of these conventions, by all means use it. Otherwise, you can use either convention. In either case, though, be consistent.
Rules for creating identifiers in JavaScript
Figure 2-6 How to create identifiers