18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Keywords<br />

ECMA-262 describes a set of keywords that ECMAScript supports. These keywords indicate beginnings<br />

and/or endings of ECMAScript statements. By rule, keywords are reserved and cannot be used as variable<br />

or function names. Here is the complete list of ECMAScript keywords:<br />

break else new var<br />

case finally return void<br />

catch for switch while<br />

continue function this with<br />

default if throw<br />

delete in try<br />

do instanceof typeof<br />

ECMAScript Basics<br />

If you use a keyword as a variable or function name, you will probably be greeted with an error message<br />

like this: “Identifier expected.”<br />

Reserved Words<br />

ECMAScript also defines a number of reserved words. The reserved words are, in a sense, words that are<br />

reserved for future use as keywords. Because of this, reserved words cannot be used as variable or function<br />

names. The complete list of reserved words in ECMA-262 Edition 3 is as follows:<br />

abstract enum int short<br />

boolean export interface static<br />

byte extends long super<br />

char final native synchronized<br />

class float package throws<br />

const goto private transient<br />

debugger implements protected volatile<br />

double import public<br />

If you use a reserved word as a variable or function name, more than likely you will not receive an<br />

error...until a future browser implements one of them. Then the word will be considered a keyword,<br />

and you will get a keyword error.<br />

Primitive and Reference Values<br />

In ECMAScript, a variable can hold one of two types of values: primitive values and reference values.<br />

❑<br />

❑<br />

Primitive values are simple pieces of data that are stored on the stack, which is to say that their<br />

value is stored directly in the location that the variable accesses.<br />

Reference values, on the other hand, are objects that are stored in the heap, meaning that the value<br />

stored in the variable location is a pointer to a location in memory where the object is stored.<br />

15

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

Saved successfully!

Ooh no, something went wrong!