|
JavaScript. The Definitive Guide Authors: Flanagan D. Published year: 2004 Pages: 13-16/767 |
Part I: Core JavaScript
|
Chapter 2. Lexical StructureThe 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 SetJavaScript 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 SensitivityJavaScript 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 |
![]() Programming PHP | ![]() JavaScript: The Good Parts | ![]() CSS: The Definitive Guide | ![]() JavaScript: The Definitive Guide: Activate Your Web Pages (Definitive Guides) | ![]() JavaScript Patterns |
![]() Programming PHP | ![]() JavaScript: The Good Parts |
![]() CSS: The Definitive Guide | ![]() JavaScript: The Definitive Guide: Activate Your Web Pages (Definitive Guides) |
![]() JavaScript Patterns |