compuhelpindia.com

JavaScript Objects

Compuhelpindia.com
« Previous                                                                                                                                       Next Chapter »


Creating JavaScript Objects
Almost "everything" in JavaScript can be objects. Strings, Dates, Arrays, Functions....
You can also create your own objects.
This example creates an object called "person", and adds four properties to it:

Example:
person=new Object();
person.firstname="Compu";
person.lastname="Help";
person.age=20;
person.eyecolor="blue"; 

Accessing Object Properties
The syntax for accessing the property of an object is:
Example:
objectName.Compuhelp
var message="Hello World!";
var x=message.length;