Javascript Object

Just like other programming language javascript support "object".In JavaScript, an object is a standalone entity, with properties, type and methods for example "Employee". A Employee" is an real word object it has properties such as name, age, pan, address etc.

Similarly Javascript objects can have properties, which define their characteristics. There are lot of ways to create an objects in Javascript below are the some more popular ways.

Using Literal Notation

This is most common way to create object in Javascript. You can create an object using literal notation. Here "Person" is the name of the new object and property1, property2... is the properties, value1, value2... is the value of each properties.

Syntax

The following example creates "Person" with four properties in which one property is created as an object with its own properties.

Javascript Creates "Person" Object Example

Javascript Reading Properties from Object Example

Javascript Removing Properties from Object Example

Using Constructor Function

Another way is to create an object in Javascript is constructor function. Define the object type by writing a constructor function and create an instance of the object with new keyword.

Javascript Reading Properties from Object Example

Javascript Adding New Properties in Object Example

Javascript Removing Properties from Object Example

Javascript Adding Method in Object Example

Javascript Invoking Method in Object Example

Javascript Loop Through Object Example

Using Object.create Method

In Javascript objects can also be created using the Object.create method. This allows you to choose the prototype object for your object you want to create, without constructor function.

Javascript Properties and Method Encapsulation Example

Javascript Comparing Object Example

Javascript Complete Object Example