Create JavaScript Structures and Objects

Part of the 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) {
//code
} // 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 types).
Var myJSON = {
"name": "Andy",
"title": "Author"
}
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();
Person.name = "Andy";
Creates an object. You can add ordinary variables (which become properties) or functions (which become methods).

Comments (0)

Leave a Reply


Post Comment

Grab a free widget and we'll bring interesting & helpful tips to your favorite personal page each day

Sign Up for RSS Feeds

Computers & Software

Inside Dummies.com