Data types

Unit 4

JavaScript Samples

Look at the samples, and view their source documents.

External file sample
The JavaScript file   sample-4-1-conversion.js   contains:
var data = "37.12hello";
document.write("data: " + data);
document.write("<br />");
document.write( "Float: " + parseFloat(data) );
document.write("<br />");
document.write( "Int: " + parseInt(data) );
document.write("<br />");
document.write("<br />");
var num1 = 37.12; // no quotes makes it a number
document.write("num1: " + num1);
document.write("<br />");
document.write( "String: " + num1.toString() );
document.write("<br />");
document.write("<br />");
var num2 = 4.23; // no quotes makes it a number
document.write("num2: " + num2);
document.write("<br />");
document.write( "String: " + num2.toString() );
document.write("<br />");
document.write("<br />");
document.write( "num1.toString() + num2.toString(): " + num1.toString() + num2.toString() );

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 3.
Sections 3.1 and 3.2 show variables and equations in mathematical format. JavaScript, like most programming languages, does not use equations, but does use assignment statements.
Section 3.2 - The book fails to distinguish between initialization, where a variable is given an initial value when it is declared, and assignment, where a variable is given a value later.
Section 3.3 - I recommend you do NOT start variable names with an underscore. Names starting with an underscore are often used in middleware or systems code.
Section 3.4 - The results in the example on page 46 should be:
JavaScript Rules! This is fun.
which is exactly the same as the result shown on page 47.
The example on page 57 is missing the </p> tag. The closing tag is required for all container elements in the current HTML standard, as well as in the XHTML standards.

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 3.

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.