What Are Object Properties?

By: Dusty Arlia
Published on September 21, 2012
Last Updated on Friday, July 17, 2015 at 11:54 PM
Total Updates: 9

The term property refers to a characteristic of an object. An example of an object would be an array. A property of an array would be its length. Here is a JavaScript example of an object property in use:

var i = shoppingCartArray.length;

In the example above, the variable i is declared and then assigned the value of the length property of the shoppingCartArray object. This value should be equal to the number of elements in the array.

Arrays are built-in JavaScript objects, that have the built-in property length. Sometimes you will want to create your own objects and properties. There are two different ways to create object properties in JavaScript:

Here is an example of an object literal:

var employee = {
first_name      : "Justin",
last_name       : "Bieber",
employee_number :  0001
};

And here is an example of dot-syntax:

employee.dob = "March 1, 1994";

Comments:

Ad: