---
title: "What is object in JS explain with example?"  
description: "What is object in JS explain with example?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93733/what-is-object-in-js-explain-with-example  
category: "web application"  
tags: ["web application development", "javascript", "web development"]  
reading_time: 2 minutes  

---

# What is object in JS explain with example?

What is [object in JS](https://answers.mindstick.com/qa/93742/what-is-work-of-math-object-in-js) [explain](https://yourviews.mindstick.com/view/86025/content-created-for-humans-not-for-bots-explain-this-statement) with example?

## Answers

### Answer by user

A javaScript object is an entity having state and behavior (properties and method). For example: car, pen, bike, chair, glass, keyboard, monitor etc. JavaScript is an object-based language. Everything is an object in JavaScript. JavaScript is template based not class based. Here, we don't create class to get the object. But, we direct create objects. **We are create object by 3 way** 1. By object literal 2. By creating instance of object directly (using new keyword) 3. By using an object constructor (using new keyword) **By object literal** Syntax:

```
 Object-name = {property1:value1, property2:value2 --- propertyN:valueN } ;
```

Example:

```
emp={id:102,name:'Shyam Kumar',salary:40000}
console.log(emp.id+' '+emp.name+' '+emp.salary);
```

**By creating instance of object directly (using new keyword)** Syntax:

```
 var objectname=new Object();
```

Example:

```
var emp=new Object();
emp.id=101;
emp.name='Ravi Malik';
emp.salary=50000;
console.log(emp.id+' '+emp.name+' '+emp.salary);
```

**By using an object constructor (using new keyword)** Syntax:

```
 function emp(arguments1, arguments2,---){
 this.property1=argument1;
 this.property2=argument2;
 this.propertyN=argumentN;
 }
```

Example:

```
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
```

```
e=new emp(103,'Vimal Jaiswal',30000);
```

```
console.log(e.id+' '+e.name+' '+e.salary);
```

\

### Answer by Ethan Karla

Javascript language is Object-Oriented Programming Langauge. Objects like C++, Java are also created in Javascript. Objects of Javascript have some methods and some properties. If viewed from the point of view of Objects, then every part of JavaScript can be made Object. But when the object is created then the 'new' keyword is used. When Number, Boolean and String are used, the 'new' keyword is used. But Array, Maths, Dates, Functions and Object are already objects.

**Objects in Javascript are created in three ways.**

1. Using Object Literal
2. Using new keyword
3. Using Object Constructor

## By object literal

```
Syntax:
Object-name = {property1:value1, property2:value2 --- propertyN:valueN } ;
Example:
emp={id:102,name:'Shyam Kumar',salary:40000}
console.log(emp.id+' '+emp.name+' '+emp.salary);
```

## By creating instance of object directly (using new keyword)

```
Syntax:
 var objectname=new Object();
Example:
var emp=new Object();
emp.id=101;
emp.name='Ravi Malik';
emp.salary=50000;
console.log(emp.id+' '+emp.name+' '+emp.salary);
```

## By using an object constructor (using new keyword)

```
Syntax:
 function emp(arguments1, arguments2,---){
 this.property1=argument1;
 this.property2=argument2;
 this.propertyN=argumentN;
 }
Example:
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
e=new emp(103,'Vimal Jaiswal',30000);
console.log(e.id+' '+e.name+' '+e.salary);
```

\


---

Original Source: https://answers.mindstick.com/qa/93733/what-is-object-in-js-explain-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
