Chapter 1. Lexical Structure
JavaScript programs are written using the Unicode character set. Unicode is a superset of ASCII and Latin-1 and supports virtually every written language currently used on the planet.
JavaScript is a case-sensitive language. This means that language keywords,
variables, function names, and other identifiers must always be typed with a
consistent capitalization of letters. The while keyword, for example, must be typed “while,”
not “While” or “WHILE.” Similarly, online, Online,
OnLine, and ONLINE are four distinct variable names.
Comments
JavaScript supports two styles of comments. Any text between
a // and the end of a line
is treated as a comment and is ignored by JavaScript. Any text between the
characters /* and */ is also treated as a comment; these comments
may span multiple lines but may not be nested. The following lines of code
are all legal JavaScript comments:
// This is a single-line comment. /* This is also a comment */ // And here is another. /* * This is yet another comment. * It has multiple lines. */
Identifiers and Reserved Words
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. A JavaScript
identifier must begin with a letter, an underscore (_), or a dollar sign
($). Subsequent characters
can be letters, digits, underscores, or dollar signs.
JavaScript reserves a number of identifiers as the keywords of the language itself. You cannot ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access