JavaScript Lecture1         

Instructor: Amadou O. Wane
Last update: 11/06/01



Javascript is a weakly-typed interpreted language created by Netscape. Java is a strongly-typed compiled language developed by Sun Microsystems.

<script language="Javascript"> statements </script>
It can be placed anywhere in the program.

String Literals vs String values (identifiers).
A literal is "as"; an identifier is an alias for another value.

Variables
A variable is a location in the memory of the computer. This location has been given a name: the variable name.
var fname = "John";


Adding numbers and strings
var mystring2 = "Hello There";
var string_num = mynumber + mystring2;
document.write("<br>The result of adding string to number: " + string_num);

Concatenation is the process of appending literals and identifiers.
var fname="John";
var lname="Doe";
//Using Concatenation
document.write("My name is:" + fname + " " + lname);

Absolute location refers to the direct location of an object. Relative location refers to the location relative to the current html document.
document.write('<img src="http://www.intechs.net/images/mytitle2.jpg">'); //Absolute location
document.write('<img src="temp/myimage.gif">'); //Relative location
document.write('<img src="mycar.gif">');// Relative location

Date
var today = new Date();
document.write("<br> Today date is: " + today);
var today2 = today.getDate();
var myTime = today.getTime();
var myYear = today.getYear();
var myYear2 = today.getFullYear();
var myHours = today.getHours();
var myMinutes = today.getMinutes();
var myMonth = today.getMonth();

Operators
var my_diff = mynumber2 - mynumber1;
document.write("<br>The difference between " + mynumber2 + " and "+ mynumber1 + " is: " + my_diff); 
var my_multi = mynumber1 * mynumber2;
var my_div = mynumber1 / mynumber2;
var my_remain = mynumber2 % mynumber1;

Post & Pre Increment 
var MyNum = 15;
MyNumIncr = MyNum++; //Post-increment, the value is incremented after 
document.write("<br>MyNumIncr :" + MyNumIncr);
MynumbAfter = MyNum;
document.write("<br>The result after the fact: " + MynumbAfter);

my_incr2 = ++mynumber1;//Pre-increment, the value is increment before
document.write("<br>The value of my_incr2 is " + my_incr2);
document.write("<br>The value of my_incr is " + my_incr);