JavaScript. The Definitive Guide
Authors: Flanagan D.
Published year: 2004
Pages: 13-16/767
Buy this book on amazon.com >>

Part I: Core JavaScript

This part of the book, Chapters 2 though 12, documents the core JavaScript language and is meant to be a JavaScript language reference. After you read through it once to learn the language, you may find yourself referring back to it to refresh your memory about some of the trickier points of JavaScript:

Chapter 2, Lexical Structure
Chapter 3, Datatypes and Values
Chapter 4, Variables
Chapter 5, Expressions and Operators
Chapter 6, Statements
Chapter 7, Objects and Arrays
Chapter 8, Functions
Chapter 9, Classes, Constructors, and Prototypes
Chapter 10, Modules and Namespaces
Chapter 11, Pattern Matching with Regular Expressions
Chapter 12, Scripting Java



Chapter 2. Lexical Structure

The lexical structure of a programming language is the set of elementary rules that specifies how you write programs in that language. It is the lowest -level syntax of a language; it specifies such things as what variable names look like, what characters are used for comments, and how one program statement is separated from the next . This short chapter documents the lexical structure of JavaScript.



2.1. Character Set

JavaScript programs are written using the Unicode character set. Unlike the 7-bit ASCII encoding, which is useful only for English, and the 8-bit ISO Latin-1 encoding, which is useful only for English and major Western European languages, the 16-bit Unicode encoding can represent virtually every written language in common use on the planet. This is an important feature for internationalization and is particularly important for programmers who do not speak English.

American and other English-speaking programmers typically write programs using a text editor that supports only the ASCII or Latin-1 character encodings, and thus they don't have easy access to the full Unicode character set. This is not a problem, however, because both the ASCII and Latin-1 encodings are subsets of Unicode, so any JavaScript program written using those character sets is perfectly valid. Programmers who are used to thinking of characters as 8-bit quantities may be disconcerted to know that JavaScript represents each character using 2 bytes, but this fact is actually transparent to the programmer and can simply be ignored.

Although the ECMAScript v3 standard allows Unicode characters anywhere in a JavaScript program, versions 1 and 2 of the standard allow Unicode characters only in comments and quoted string literals; all elements are restricted to the ASCII character set. Versions of JavaScript that predate ECMAScript standardization typically do not support Unicode at all.



2.2. Case Sensitivity

JavaScript is a case-sensitive language. This means that language keywords, variables , function names , and any 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.

Note, however, that HTML is not case-sensitive (although XHTML is). Because of its close association with client-side JavaScript, this difference can be confusing. Many JavaScript objects and properties have the same names as the HTML tags and attributes they represent. While these tags and attribute names can be typed in any case in HTML, in JavaScript they typically must be all lowercase. For example, the HTML onclick event handler attribute is sometimes specified as onClick in HTML, but it must be specified as onclick in JavaScript code (or in XHTML documents).


JavaScript. The Definitive Guide
Authors: Flanagan D.
Published year: 2004
Pages: 13-16/767
Buy this book on amazon.com >>

Similar books on Amazon