Presented at ~conf July 14, 2003 by Andrew Hedges, Design Team Manager, Interactive Multimedia Applications Group
Basic features of JavaScriptJavaScript shares most of the features of common programming languages. If you are already familiar with Perl or C, a lot of the following will look familiar. If you’re not … well, it’s time to get familiar! |
Variables
|
Code Examplesvar a = 4; a = 4; myString = "Welcome to my world." |
Arrays
|
Code Examplesvar myArray = new Array(); myArray[0] = "red"; myArray[1] = "white"; myArray[2] = "blue"; numbersArray = new Array(0,1,2,3,4,5,6,7,8,9); nominalArray = new Array(); nominalArray["favcolor"] = "green"; nominalArray["favfood"] = "pizza"; |
Objects
|
Code Examplesvar workshop = new Object(); workshop.title = "Introduction to JavaScript"; alert("Welcome to " + workshop.title); |
Methods
|
Code Examplesalert("Hello world!"); bodyObject = document.getElementById("bodyDiv"); lowercaseString = myString.toLowerCase(); |
Conditional statements
|
Code Examplesif (name == "Andrew") alert("Hello, Andrew!"); if (name == "Andrew") { alert("Hello, Andrew!"); } else { alert("Hello, world!"); } |
Loops
|
Code ExamplesnamesArray = new Array("Dan","Rob","Kim"); for (i = 0; i < namesArray.length; i++) { alert("Hello, " + namesArray[i] + "!"); } |
Comments
|
Code Examples// this is a one line comment /* this is a comment that is on more than one line */ |
Event handlers
|
Code Examples<body onload="showAlert()"> <a href="#" onclick="window.open('popup.html','myPopUp')"> <a href="#" onmouseover="swapImage('cat_active')" onmouseout="swapImage('cat_inactive')"> |
Get excited because it’s time for another quiz!
Document URL: http://www.gwu.edu/~ahedges/javascript/
Copyright © 2003, The George Washington University. All rights reserved.