Math, Date, strings, and arraysObject in order to assign attributes to it
<script type="text/javascript">
function square(x)
{
return x * x;
}
// Functions as variable values
var t = square;
document.write("The square of 2 is " + t(2) + "<br/>");
// Functions as subroutine arguments
function apply (func,value)
{
return func(value);
}
document.write("The square of 3 is " + apply(square, 3) + "<br/>");
// Functions as object attributes
var o = new Object;
o.sq = square;
document.write("The square of 4 is " + o.sq(4) + "<br/>");
// Functions as array elements
var a = new Array(20);
a[5] = square;
document.write("The square of 5 is " + a[5](5) + "<br/");
</script>
this (just as in C++)
<script type="text/javascript">
function Person_toString()
{
return this.name+', '+this.address+', '+this.phone;
}
function Person_toTable() {
return "<table border=\"1\"><tr><td>" + this.name
+ "</td></tr><tr><td>" + this.address
+ "</td></tr><tr><td>" + this.phone
+ "</td></tr></table>";
}
function Person_toList() {
return "<ul>\n<li>" + this.name
+ "</li>\n<li>" + this.address
+ "</li>\n<li>" + this.phone
+ "</li>\n</ul>";
}
var p = new Object;
p.name = 'The Barack';
p.address = '1600 Pennsylvania Avenue';
p.phone = '(111) 111-1111';
p.toString = Person_toString;
p.toTable=Person_toTable;
p.toList=Person_toList;
document.write("p is " + p + "<br/>\n");
document.write("p.toTable() is " + p.toTable() + "<br/>\n");
document.write("p.toList() is " + p.toList() + "<br/>\n");
</script>
<script type="text/javascript">
function circle_area()
{
return Math.PI * this.radius * this.radius;
}
function circle_inside(x, y)
{
var xd = this.x - x;
var yd = this.y - y;
var dist = Math.sqrt(xd * xd + yd * yd);
return dist < this.radius;
}
function Circle (r, x, y)
{
this.radius = r;
this.x = x;
this.y = y;
this.area = circle_area;
this.inside = circle_inside;
}
var circle = new Circle(3, 4.5 , 5.3);
document.write("Circle area is " + circle.area() + "<br/>");
if (circle.inside(2, 2)) {
document.write("(2, 2) is inside the circle<br/>");
}
else {
document.write("(2, 2) is outside the circle<br/>");
}
if (circle.inside(4, 5)) {
document.write("(4, 5) is inside the circle<br/>");
}
else {
document.write("(4, 5) is outside the circle<br/>");
}
</script>
innerHTML<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/XHTML1/DTD/XHTML1-strict.dtd"> <html xmlns="http://www.w3.org/1999/XHTML" xml:lang="en" lang="en"> <head> <title>Page Title</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-us" /> </head> <body> <h1>This is a heading</h1> <p>A paragraph with a <a href="http://www.google.com/">link</a>.</p> <ul> <li>a list item</li> <li>another list item</li> <li>a third list item</li> </ul> </body> </html>

<table>
<tbody>
<tr>
<td>Shady Grove</td>
<td>Aeolian</td>
</tr>
<tr>
<td>Over the River, Charlie</td>
<td>Dorian</td>
</tr>
</tbody>
</table>
window - The browser window
window.close() - Closes the current windowwindow.pageYOffset - Sets or returns the Y position of the current page in relation to the upper left corner of a window's display areanavigator - Information about the web browser you are using
navigator.userAgent - Returns the value of the user-agent header sent by the client to the serverscreen - Information about the screen occupied by the web brower
screen.width - Returns width of the display screenhistory - List of pages the user has visiteds
history.go(-1) - Go back to the previous page (if any)location - URL of the current document
location.pathname - Sets or returns the path of the current URLdocument - Current HTML page object model
document.getElementsByTagName("some tag") - Get all elements of a certain type; returns an arrayvar element = document.getElementById("some ID") - Get a specific element on the page; returns an element
element.getElementsByTagName("some tag") - Same as above; returns an arraydocument.createElement("some element")firstChild, lastChild - Start/end of this node's list of childrenchildNodes - Array of all this node's childrennextSibling, previousSibling - Neighboring nodes that have the same parentparentNode - The element that contains this nodecreateElement(), createTextNode()appendChild(node) - Add given node at the end of this node's child listremoveChild(node) - Remove given node from this node's child listreplaceChild(newChild, oldChild) - Replace old child node with the given new nodeinsertBefore(newChild, oldChild) - Add given new node in this node's child list just before oldChild
<people>
<person first-name="eric" middle-initial="H" last-name="jung">
<address street="321 south st" city="denver" state="co" country="usa"/>
<address street="123 main st" city="arlington" state="ma" country="usa"/>
</person>
<person first-name="jed" last-name="brown">
<address street="321 north st" city="atlanta" state="ga" country="usa"/>
<address street="123 west st" city="seattle" state="wa" country="usa"/>
<address street="321 south avenue" city="denver" state="co" country="usa"/>
</person>
</people>
var doc = document.implementation.createDocument("", "", null);
var peopleElem = doc.createElement("people");
var personElem1 = doc.createElement("person");
personElem1.setAttribute("first-name", "eric");
personElem1.setAttribute("middle-initial", "h");
personElem1.setAttribute("last-name", "jung");
var addressElem1 = doc.createElement("address");
addressElem1.setAttribute("street", "321 south st");
addressElem1.setAttribute("city", "denver");
addressElem1.setAttribute("state", "co");
addressElem1.setAttribute("country", "usa");
personElem1.appendChild(addressElem1);
var addressElem2 = doc.createElement("address");
addressElem2.setAttribute("street", "123 main st");
addressElem2.setAttribute("city", "arlington");
addressElem2.setAttribute("state", "ma");
addressElem2.setAttribute("country", "usa");
personElem1.appendChild(addressElem2);
var personElem2 = doc.createElement("person");
personElem2.setAttribute("first-name", "jed");
personElem2.setAttribute("last-name", "brown");
var addressElem3 = doc.createElement("address");
addressElem3.setAttribute("street", "321 north st");
addressElem3.setAttribute("city", "atlanta");
addressElem3.setAttribute("state", "ga");
addressElem3.setAttribute("country", "usa");
personElem2.appendChild(addressElem3);
var addressElem4 = doc.createElement("address");
addressElem4.setAttribute("street", "123 west st");
addressElem4.setAttribute("city", "seattle");
addressElem4.setAttribute("state", "wa");
addressElem4.setAttribute("country", "usa");
personElem2.appendChild(addressElem4);
var addressElem5 = doc.createElement("address");
addressElem5.setAttribute("street", "321 south avenue");
addressElem5.setAttribute("city", "denver");
addressElem5.setAttribute("state", "co");
addressElem5.setAttribute("country", "usa");
personElem2.appendChild(addressElem5);
peopleElem.appendChild(personElem1);
peopleElem.appendChild(personElem2);
doc.appendChild(peopleElem);