JavaScript Tutorials - Herong's Tutorial Examples

https://www.herongyang.com/JavaScript

Copyright © 2002-2023 Herong Yang. All rights reserved.

JavaScript Tutorials This book is a collection of tutorial examples and notes written by the author while he was learning JavaScript. Topics include ECMAScript specifications; data types, variables and expressions; flow control statements: 'if', 'for', 'switch', and 'while'; using arrays and objects; defining and calling functions; embedding JavaScript code in HTML documents; DOM (Document Object Model) API levels; using the JavaScript console in Web browsers; creating new object types with prototypes; building prototype inheritance hierarchy; managing functions as objects; using jrunscript JavaScript shell; sending AJAX (XMLHttpRequest) requests. Updated in 2023 (Version 2.33) with AJAX tutorials.

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 Literals

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

type="text/javascript" or language="JavaScript"

JavaScript Version Supported by Browsers

Including 'script' Tags in String Literals

Escaping 'script' Tags in String Literals

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

JavaScript Console in Google Chrome

JavaScript Console in Mozilla Firefox

JavaScript Console in Apple Safari

JavaScript Console in IE (Internet Explorer)

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

'jrunscript' - JavaScript Shell Command from JDK

Downloading and Installing JDK 10

"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

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 "JSON" Object Type - parse() and stringify()

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

AJAX (Asynchronous JavaScript And XML)

References

Full Version in PDF/EPUB

Keywords: JavaScript, Web, DOM, JSON