Create JavaScript Structures and Objects - dummies

Create JavaScript Structures and Objects

By Andy Harris

Part of JavaScript & AJAX For Dummies Cheat Sheet

JavaScript allows you to put together code lines to create functions and variables to create arrays. You can put functions and variables together to create objects.

Element Description
function fnName(parameters) {
} // end function
Defines a function named fnName and
sends it parameters. All code inside function will execute when the
function is called.
var myArray = new Array("a",
"b", "c");
Creates an array. Elements can be any type (even mixed
Var myJSON = {


Creates a JSON object. Each element
has a name/value pair, and can contain anything, including an array
(with square braces) another JSON object,
or a function.
Var person = new Object(); =
Creates an object. You can add ordinary variables (which become
properties) or functions (which become methods).