Last Modified: 1/29/08
  Computer Training
JavaScript Statements and Structure

Credit: Kirk Born (St Sci/NASA)

Elements of JavaScript

We explain JavaScript mostly through examples. We assume that you are familiar with "C-like" languages and so will not discuss those elements of the language that are similar to "C".

Client-Side JavaScript:

  • has a large number of reserved words: the following words are absolutely, positively reserved:
    break    false    in     this   void
    continue for      new    true   while
    delete   function null   typeof with
    else     if       return var
         
    plus about 120 or so words that are sorta reserved or might be reserved in the future. See the complete list in David Flannagan's "JavaScript, the Definitive Guide".

  • uses many conventional "C"-like structures such as assignments, expressions, if-then-else statements, switch (similar to "case" statements), functions, etc., along with a few new ones such as "new ", "typeof", "+" used for string concatenation, "for (prop in object)...", and "with (object)..."

  • provides extensive support for strings in terms of their declaration, concatenation, splitting, and substring operations such as locating, extracting, and manipulating substrings. In addition, it provides full support for "Perl" regular expressions which operate on strings. See Test of Strings

  • provides functions which differ in many ways from those in "C-like" languages. See Functions and Arguments for many of the important features of JavaScript functions.

  • supports arrays which also differ from those in most other languages. See Test of Arrays for many of their features.

  • provides timimg controls and date-time functions which let it interact with real-world events. See Timing Controls and Date-Time Functions

  • uses a somewhat different value vs reference model then most other languages. JavaScript, like many languages, makes a distinction between value versus reference, particularly in terms of copies, comparisons, and arguments. Basically, Booleans and numbers, are copied, passed, and compared by value, where as most others (objects, arrays, and functions) are copied, passed, and compared by reference. Strings, however, are different: they cannot be modified or changed. The following table from Flannagan's "JavaScript: the Definitive Guide" summarizes the way various types are manipulated:

    TypeCopied ByPassed ByCompared By
    Numbervaluevaluevalue
    Booleanvaluevaluevalue
    Stringimmutableimmutablevalue
    Objectreferencereferencereference
    Arrayreferencereferencereference
    Functionreferencereferencereference

    See this for some effects of value-versus-reference handling in functions.

Previous Home Next

Course Topics

Major Concepts in JavaScript

Execution of JavaScript Programs

JavaScript Statements and Structures

JavaScript as an Object Oriented Language

The Document Object Model

Programming with JavaScript

JavaScript and DHTML

Using Cookies in JavaScript

Using JavaScript to Write HTML

 
Previous Home Next

Other Topics:   JavaScript Tutorials   |   Cut and Paste JavaScript   

©1999 UW Technology