- Scripting language
- + Can interact with user and browser (client)
- - Can't interact with server and database
- Arithmetic
var num1 = 5, num2 = 10;
num2 = num1 + num2;
num1 = num1 * 5;
num2 -= 15; // num2 = num2 - 15;
num1++; // num1 = num1 + 1;
- Strings
var name = "James" + "Bond";
- Lists of related data (same type)
- Index starts at 0 not 1
var nums = new Array(5, 31, 91);
var colors = [ "pink", "blue" ];
colors.push("silver");
if( colors[1] == "blue" ) { ... }
if( colors.length == 3 ) { ... }
- Groups of related properties
var car = {
make : "Volvo",
model : "P1800",
transmission : "automatic",
cylinders : 4
}
if( car.make == "Saab" ) { ... }
Animals!
- "for" can be used as a counter
for( var i=1; i<=5; i++ ) { ... }
- Or to loop through an array
var animals = [ "ferret", "turtle", "lemur" ];
for( var i=0; i<animals.length; i++ ) {
$('#'+animals[i]).fadeToggle(1000);
}