Read: Chapter 2
Create: Simple Calculator and Link to Homework page!
Review: What is a Web Developer (Job requirements)
Best Practices (I don't agree with all of these)
The display difference between document.write(variable) or getElementById("myid").innerHTML = variable
Numerical (123..), text (string) and boolean (True - False)
A variable is a placeholder or container for use within the program. You should but you don't have to declare your variables.
Syntax for Variables
- Variable names are case sensitive
- They must begin with a letter or the underscore
- The variable must not use a reserved word
Global vs Local variables: When you declare a variable within a function, the variable can only be accessed within that function.
Operator Description Example Result + Addition x=4
6 - Subtraction x=5
2 * Multiplication x=5
30 / Division 20/5
% Modulus (division remainder) 5%2
++ Increment x=8
x=9 -- Decrement x=9
Operator Example Is The Same As = x=y x=y += x+=y x=x+y -= x-=y x=x-y *= x*=y x=x*y /= x/=y x=x/y %= x%=y x=x%y
Operator Description Example == is equal to 6==7 returns false ===
is equal to
The difference is it checks both value and type!
x==y returns true
x===y returns false
!= is not equal 9!=8 returns true > is greater than 2>7 returns false < is less than 7<9 returns true >= is greater than or equal to 6>=7 returns false <= is less than or equal to 1<=6 returns true
+ is used for concatination and for addition. You have to pay attention to how the data is classified (number or string). If you need to make sure a variable is a number, use Number() methnod.
Example: X =A + B can be written as X=Number(A) + Number(B)
Varialbes on steroids. You can have single or multi-demansional arrays
var arrayName = new Array();
var airplane = new Array();
airplane = "747";
airplane = "787";
airplane = "777";
var arrayName = ["747", "787", "777", "737"];
var airplane= ["747", "787", "777", "737"];