JavaScript Tutorials - Herong's Tutorial Examples

http://www.herongyang.com/JavaScript

Copyright © 2013 by Dr. Herong Yang. All rights reserved.

JavaScript Tutorials This free book is a collection of tutorial examples and notes written by the author while he was learning JavaScript. Topics include data type, variable, expression, statement, loop, user function, object, property, method, array, object, constructor, prototype.

Table of Contents

About This Book

Introduction to JavaScript

What Is JavaScript?

First JavaScript - "Hello World!"

Walking through the First JavaScript

The document.write() Method

ECMAScript Language Specification and JavaScript Dialects

JavaScript History and Versions

ECMAScript Language Specification

Automatic Semicolon Insertion to End Statements

Data Types, Variables and Expressions

Primitive Data Types - Numbers, Strings, and Booleans

Numeric Value Literals

String Literials

Declaring Variables - "var" Statements

Operators and Expressions

Operators and Expressions - Examples

Flow Control Statements

What Is a Statement?

Conditional "if" Statements

Conditional "if" Statement Examples

"switch ... case" Statements

"switch ... case" Statement Example

"for" Loop Statements

"for" Loop Statement Example

"while" Loop Statements

"while" Loop Statement Example

Creating, Accessing, and Manipulating Arrays

What Is an Array?

Creating an Array Object

Accessing Array Elements with Indexes

Truncating and Iterating Array Elements

Array Object Instance Methods

Array Object Instance Method Examples

Defining and Calling Functions

Defining Your Own Functions

Defining Your Own Functions - Example

Calling Your Own Functions - Example

Passing Parameters by Value or by Reference

Function Parameters Are Passed as Local Copies

Function Parameters Are Passed as Local Copies - Example

Global and Local Variables - Scope Rules

Global Variables - Examples

Local Variables - Examples

Collision of Global and Local Variables - Examples

"return" Statement and Return Value

Web Browser Supporting JavaScript

JavaScript Support in Web Browsers

Including JavaScript Codes with HTML "script" Tags

Including 'script' Tags in String Literials

Escaping 'script' Tags in String Literials

Using HTML Entities to Protect HTML Tags

Including JavaScript Codes as External Files

DOM API - The "document" Object

DOM API - The "window" Object

DOM API - The "window.open" Method

Event Listeners and Objects

'javascript:' Pseudo-URL Addresses

Server-Side and Client-Side Web Scripting

Web Scripting Architecture Overview

Server-Side Scripting Overview

Client-Side Scripts for Document Updating

Client-Side Scripts for Event Handling

Client-Side Scripting Processed Multiple Times

New Script Resulted from Two Original Scripts

Introduction to Objects

What Is an Object?

Objects of "Object" Data Type

Adding and Deleting Object Own Properties

Adding and Deleting Object Own Methods

Using "this" Keyword to Represent Current Object

Object Literals of the "Object" Type

Objects and Associate Arrays

Objects with Indexed Properties

Differences between "Object" and "Array"

Using "Array" Objects as "Object" Objects

Defining Your Own Object Types

Prototype-Dased Object-Oriented Programming Style

Prototype-Based Programming Features in JavaScript

Defining Object Constructor Functions

Adding Properties and Methods to Objects

"for ... in" and "for each ... in" Statements

"prototype" Property of the Constructor Function Object

"instanceof" Operator - Determining Object Type

"typeof" Operator and Data Types

Inheritance of Properties and Methods through the Prototype Object Chain

Inheriting from Constructor's Prototype Object

Changing the Constructor's Prototype Object

Inheriting Properties from Two Level Prototype Objects

Built-in Properties and Methods in "Object.prototype"

Using "hasOwnProperty()" Method to Test Inherited Properties

Setting the "constructor" Property in the "prototype" Object

Adding Local Methods at the Object Level

Adding Inherited Methods at the Prototype Level

Building Multiple Levels of Prototype Objects

Prototype Object Chain Summary

'jrunscript' - JavaScript Shell Command from JDK

Downloading and Installing J2SE 1.6.0 on Windows

"jrunscript" - Scripting Shell Command and Options

Running JavaScript Code with 'jrunscript'

Evaluating JavaScript Code with 'jrunscript' Interactively

Running a JavaScript Code File with 'jrunscript'

Using Functions as "Function" Objects

Functions Are Objects of the "Function" Type

Using the Function Constructor

Function Object Inherited Properties and Methods

Function Object Instance Properties

Creating Function Objects with "function" Statements

Creating Function Objects with the "function" Operator

Comparing 3 Ways of Creating Functions

Introduction to Built-in Object Types

Overview of Built-in Object Types

The "Object" Object Type - The Root Object Type

The "Global" Object Type - The Invisible Global Container

Global Properties and Functions Defined in ECMAScript

Global Properties and Functions Provided by "jrunscript"

The "Function" Object Type - Functions Are Objects

The "Array" Object Type - Arrays Are Objects

The "String" Object Type - Not Equal to String Primitive Type

The "Boolean" Object Type - Wrapping Boolean Values into Objects

The "Number" Object Type - Not Equal to Number Primitive Type

The "Date" Object Type - Managing Dates and Times

The "RegExp" Object Type - Regular Expression Patterns

The "Error" Object Type - Runtime Exceptions

The "Math" Object Type - The Math Container

W3C's Document Object Model (DOM) Specifications

Overview of DOM Specifications

DOM Level 0 - Example

DOM Level 1 - Example

DOM Level 2 - Example

DOM Level 3 - Example

DOM Level Test - document.implementation.hasFeature

Inheritance vs. Flattened Views of the API

A Web Document as A Tree of Different Interfaces

A Web Document as A Tree of Nodes

Dump Document in a New Window - JavaScript Source

Dump Document in a New Window - Firefox 2.0 Result

Dump Document in a New Window - IE 6.0 Result

References

PDF Printing Version

Keywords: JavaScript, Web, Tutorial, Example