11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 2-1: Basic Terminology of Programming Languages<br />

Name Definition Examples<br />

simply a list of statements. {<br />

alert("Hello there");<br />

}<br />

Keyword A word that is a part of the language itself.<br />

Keywords may not be used as identifiers.<br />

Reserved<br />

Word<br />

A word that might become a part of the<br />

language itself. Reserved words may not be<br />

used as identifiers, although this restriction<br />

is sometimes not strictly enforced.<br />

Language Characteristics<br />

while<br />

do<br />

function<br />

var<br />

class<br />

public<br />

When studying a new programming language it is important to detail its major characteristics,<br />

such as how code is executed, whitespace is interpreted, statements indicated, and so on. This<br />

section covers these basic issues and should be understood before we talk about the various<br />

data types, operators, and statements provided by <strong>JavaScript</strong>.<br />

Script Execution Order<br />

<strong>JavaScript</strong> code found in (X)HTML documents is interpreted line by line as it is found in the<br />

page. This means that it is a good idea to put function definitions and variable declarations in<br />

the document head, enclosed by the … tags, if they will be used<br />

throughout the page. Certain code—for example, the bodies of functions and actions<br />

associated with event handlers—is not immediately executed.<br />

Case Sensitivity<br />

<strong>JavaScript</strong> is case-sensitive. This means that capital letters are distinct from their lowercase<br />

counterparts. For example, if you use the identifiers result, Result, and RESULT in your script,<br />

each identifier refers to a separate, distinct variable. Case sensitivity applies to all aspects of<br />

the language: keywords, operators, variable names, event handlers, object properties, and so<br />

on. All <strong>JavaScript</strong> keywords are lowercase, so when using a feature like an if statement, you<br />

need to make sure you type if and not If or IF. Because <strong>JavaScript</strong> uses the ―camel-back‖<br />

naming convention, many methods and properties use mixed casing. For example, the M in the<br />

name of the lastModified property of the Document object must be uppercase; using a<br />

lowercase m will retrieve an undefined value.<br />

<strong>The</strong> primary implication of case sensitivity is that you should pay close attention to capitals<br />

when defining and accessing variables, when using language constructs like if and while, and<br />

when accessing properties of objects. One typo can change the meaning of your whole script<br />

and require significant debugging effort.<br />

Note One exception to <strong>JavaScript</strong>’s case sensitivity is Internet Explorer 3. In this particular<br />

browser, client-side objects and properties are case-insensitive. This exception does not<br />

pose a problem for scripts you might write today. It merely means that some older scripts<br />

relying on Internet Explorer’s case insensitivity might not work in modern browsers.<br />

HTML and Case Sensitivity<br />

Under HTML 4 and earlier, element and attribute names are case-insensitive. For example, the<br />

following two tags are equivalent:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!