Bo dinglesTM - -   Bright Lightbulb Graphic Ideas   - -

The Web Developer Bootcamp 2024

Colt Steele

Back to JavaScript Index Page


JavaScript Objects

JavaScript Objects PDF

W3Schools JavaScript Objects

MDN JavaScript Objects

An object is a collection of properties, and a property is an association between a key and a value.

An array is another form of an Object and with an array, you reference a property with an index value. With "Literal" objects, you reference a value by it's key. Arrays are considered "ordered" because they store data in an ordered fashion, starting at index(0), from left to right. Literal objects store data in an unordered fashion, referenced by their key/value as opposed to an index value.

*note: A property's value can be a function, in which case the property is known as a method.

Objects in JavaScript, just as in many other programming languages, can be compared to objects in real life. In JavaScript, an object is a standalone entity, with properties and type. Compare it with a cup, for example. A cup is an object, with properties. A cup has a color, a design, weight, a material it is made of, etc. The same way, JavaScript objects can have properties, which define their characteristics.

In addition to objects that are predefined in the browser, you can define your own objects.


The basic syntax is:

  • objectName = {
    • key1 : value1,
    • key2 : value2,
    • key3 : value3,
    • key4 : value4
  • }

To access a value just reference the objectName["key"], or by using the "dot" notation objectName.key.

For example:

  • objectName["key1"] returns value1
  • (dont forget the square brackets and quotations)
  • or objectNmae.key2 returns value2

Let's say we're describing a car, we could build the car object

  • const car = {
    • color: 'Red',
    • doors: 4,
    • sunroof: false,
    • cost: '$'' + 20000
  • }

Now we can access the car properties:

  • car["color"] returns Red
  • car["cost"] returns $20000
  • car.doors returns 4
  • car.sunroof returns false



Back to Top