Open In App

What is an Object in JavaScript ?

An object in JavaScript is a non-primitive data type that is used to store multiple values of different primitive data types in the form of key-value pairs.

A JavaScript object can be created using the following ways:



Example: The below code implements the above approaches to create an object in JavaScript.




// Object literal
const obj1 = {name: "Virat", age: 23}
 
// Object constructor
const obj2 = new Object();
obj2.name="GFG";
 
// Object.create() method
const obj3 = Object.create(obj2);
obj3.name = "Rohit";
 
console.log(obj1, obj2, obj3);

Output

{ name: 'Virat', age: 23 } { name: 'GFG' } { name: 'Rohit' }
Article Tags :