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) {
} // 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(); = "Andy";
Creates an object. You can add ordinary variables (which become properties) or functions (which become methods).
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus