JavaScript: The Definitive Guide

Previous Chapter 2
Lexical Structure
Next
 

2.6 Identifiers

An identifier in JavaScript is a name used to refer to something else. That is, it is a variable or function name. The rules for legal identifier names are the same in JavaScript as they are in most languages. The first character must be a letter (lowercase or uppercase) or an underscore (_). Subsequent characters may be any letter or digit or an underscore. (Numbers are not allowed as the first character so that JavaScript can easily distinguish identifiers from numbers.) These are legal identifiers:

i
my_variable_name
v13
_dummy

In Navigator 3.0, the $ character is also legal in JavaScript identifiers, in any position including the first. This change was made for compatibility with Java identifiers. Therefore, in Navigator 3.0 scripts, the variable names in the following assignments are also legal:

A$ = "I'm a BASIC programmer";
$VMS = true;

Internet Explorer 3.0 does not support $ in identifier names, but a future version of the language will.


Previous Home Next
Literals Book Index Reserved Words

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell