Except where otherwise noted, the contents of this presentation are Copyright 2010 Marty Stepp and Jessica Miller.
body (example)<script type="text/javascript"> JavaScript code </script>
head or bodydocument.write
document.write("message");
bodydocument.writetypeof functiontypeof(value)
function foo() { alert("Hello"); }var a = ["Huey", "Dewey", "Louie"];true:
typeof(3.14) === "number"typeof("hello") === "string"typeof(true) === "boolean"typeof(foo) === "function"typeof(a) === "object"typeof(null) === "object"typeof(undefined) === "undefined"arguments array
function example() {
for (var i = 0; i < arguments.length; i++) {
alert(arguments[i]);
}
}
example("how", "are", "you"); // alerts 3 times
arguments representing the parameters passed
for (var name in arrayOrObject) {
do something with arrayOrObject[name];
}
var map = []; map[42] = "the answer"; map[3.14] = "pi"; map["champ"] = "suns";
Map collection or a hash table data structurevar today = new Date(); // today var midterm = new Date(2007, 4, 4); // May 4, 2007
getYear returns a 2-digit year; use getFullYear insteadgetDay returns day of week from 0 (Sun) through 6 (Sat)getDate returns day of month from 1 to (# of days in month)Date stores month from 0-11 (not from 1-12)eval (evil?) function
eval("JavaScript code");
eval("var x = 7; x++; alert(x / 2);"); // alerts 4
eval treats a String as JavaScript code and runs that code