Expressions and statements

Unit 5

Operators

Look at the samples 5-1-operators. It shows the JavaScript operation, and the resulting value.

You can copy sample5-1.operators.html and sample5-1.operators.js
You can change sample5-1.js to demonstrate different operators, if you wish. Notice that the entire contents of the body are built using JavaScript.

Functions

Look at the samples 5-2-functions. It shows the JavaScript functions, and function invocation.

The contents of sample-5-2-functions.js are:

sayHello();
saySomething("What's up Doc?");
saySomething();

function sayHello()
  {
  alert("hello");
  }

function saySomething(it)
  {
  // use an empty string if it is undefined
  var aString = it == undefined ? "" : it ;  
  alert("The word is: " + aString);
  }
          

Notice the use of the ternary operator to change undefined to "".

Lab 2

In lab 2 you will build one more page.

Put your web page on the Internet

Put your page on the Internet.

Test your page

Validate your page before trying to get the JavaScript to work. Then make sure the JavaScript works.

Complete lab 2

You have done all the work for lab 2.
Now, send note to instructor.

Reading assignment

Reading assignments are in the text book, Java Script, A Beginner's Guide, Second Edition, by John Pollock; McGraw Hill / Osborne, ISBN 0-07-222790-7

Read Module 5.

The book does not discuss strings until later. You should know these two string operators:
The + operator concatenates two strings. Example using +:

"Hello" + " " + "there"
This evaluates to:
"Hello there"
          

The += operator takes the value out of the left-hand operand, concatenates the value of the right-hand operand, and puts the result back in the left-hand operand. Example using +=:

x = "hello";
y = "there";
x += y;
This evaluates to:
"hellothere"
          

Sections 5.1, 5.2, and 5.3 show operators that are similar to other programming languages. Skim this material, and look at anything that looks unfamiliar.
Section 5.4 - Read carefully the description of === and !== - Look carefully at how they differ from == and != - Skim the other material, and look at anything that looks unfamiliar.
Section 5.5 - Read the section on Special Operators. The description of instanceof is a little strange, because there are no real types in JavaScript. I suggest you ignore the instanceof operator until you look at creating objects. Skim the other sections in 5.5, and look at anything that looks unfamiliar.

Alternate reading assignments are in the text book, Java Script Concepts & Techniques Programming Interactive Web Sites, by Tina Spain McDuffie; Franklin, Beedle & Associates, ISBN 1-887902-45-7

Read Chapter 4.

Lecture notes

Do NOT read the lecture notes before hearing the lecture. If you do, you will find the lecture very boring. Read the lecture notes if you do not attend the lecture, or if you wish to review the material.