Section 2.7. Identifiers


2.7. Identifiers

An identifier is simply a name. In JavaScript, identifiers are used to name variables and functions, and to provide labels for certain loops in JavaScript code. The rules for legal identifier names are the same in JavaScript as they are in Java and many other languages. The first character must be a letter, an underscore (_), or a dollar sign ($).[*] Subsequent characters can be a letter, a digit, an underscore, or a dollar sign. (Digits are not allowed as the first character so that JavaScript can easily distinguish identifiers from numbers.) These are all legal identifiers:

[*] Note that prior to JavaScript 1.1, dollar signs are not legal in identifiers. They are intended for use only by code-generation tools, so you should avoid using dollar signs in identifiers in the code you write yourself.

 i my_variable_name v13 _dummy $str 

In ECMAScript v3, identifiers can contain letters and digits from the complete Unicode character set. Prior to this version of the standard, JavaScript identifiers were restricted to the ASCII character set. ECMAScript v3 also allows Unicode escape sequences to appear in identifiers. A Unicode escape contains the characters \u followed by four hexadecimal digits that specify a 16-bit character encoding. For example, the identifier π can also be written as \u03c0. Although this is an awkward syntax, it makes it possible to translate JavaScript programs that contain Unicode characters into a form that allows them to be manipulated with text editors and other tools that do not support the full Unicode character set.

Finally, identifiers can't be the same as any of the keywords used for other purposes in JavaScript. The next section lists the special keywords that are reserved in JavaScript.




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net