JS Objects

      No Comments on JS Objects

Before learning about JS Objects, we will first know what objects are actually in real life. In real life say a car is an object. A car has properties like brand, color, size ,shape , capacity and more, All cars have same properties There are some functions that can be applied on to an object

JS Objects

We have learned a variable is something that can hold a value. For example
var car='honda';. Here car is a variable holding a value “honda”.
Similarly an object i s also a variable, but an object can hold many values. For example var car = {type:"honda", model:"500", color:"white"};

Object Properties

The name:values pairs (in JavaScript objects) are called properties.
For example var car = {type:"honda", model:"500", color:"white"};
Here object car have properties:

  • type
  • model
  • color

Object Methods

Methods are actions that can be performed on objects.

Object Declaration

You define (and create) a JavaScript object with an object literal:
For example var car = {type:"honda", model:"500", color:"white"};

Accessing Object Properties

Object properties are accessed in two ways:

  • objectName.propertyName;
  • objectName[“propertyName”];

Accessing Object Methods

Methods are accessed using following syntax:


Leave a Reply

Your email address will not be published. Required fields are marked *