Introduction to JavaScript

This lecture notes is based on Prof Doreen De Leon's lectures.

Reading

Sebesta Chapter 4

Uses

Basics

Reserved Words in JavaScript

Primitive Types

Numeric and String Literals

  1. Numeric literals
  2. String literal

Other primitive types

Variables

Numeric Operators

The Math Object

The Number Object

String Concatenation

Implicit Type Conversions

Some String Properties and Methods

Predefined String Functions

The typeof Operator

Returns the type of its single operand ("number", "string", "boolean") or "object" if the operand is an object or "null".

Assignment Statements

Same as C++: +=, -=, *=, /=, %=

Screen Output

Write a line of text to an HTML document (Document object)

  1. writeln
  2. write
  3. Can use <br /> in a write or writeln argument to get multiple lines of text
    Example:
    document.writeln("<h1>Happy Days<br />Are Here Again</h1>");
    // displays: Happy Days
    //           Are Here Again
    // as a level 1 header

Printing a line (or lines) in a dialog box (Window object)

Equality/Relational Operators

Control Structures

Boolean Conditions

Compound Conditions

Uses short-circuit evaluation, like C++ and Perl.

if-else

switch statement

Same as in C++

Loops

Functions

Object Creation and Modification

Arrays

Array Object Creation

Length of an array

Array methods

Constructors

Pattern Matching