Clean β’ Professional
JavaScript provides multiple ways to create objects, each suited for different scenarios. Choosing the right method depends on your needs, such as simplicity, reusability, or inheritance.

The simplest and most common way to create an object, using curly braces {} to define key-value pairs directly.
const person = {
name: "Alice",
age: 25,
greet: function() {
console.log(`Hello, my name is ${this.name}`);
}
};
console.log(person.name); // "Alice"
person.greet(); // "Hello, my name is Alice"
new Object()Objects can also be created using the built-in Object constructor:
const person = new Object();
person.name = "Bob";
person.age = 30;
person.greet = function() {
console.log(`Hello, my name is ${this.name}`);
};
person.greet(); // "Hello, my name is Bob"
A constructor function is a custom function designed to create multiple similar objects:
this to define properties and methods.new keyword.function Person(name, age) {
this.name = name;
this.age = age;
this.greet = function() {
console.log(`Hello, my name is ${this.name}`);
};
}
const person1 = new Person("Charlie", 28);
const person2 = new Person("Diana", 32);
person1.greet(); // "Hello, my name is Charlie"
person2.greet(); // "Hello, my name is Diana"
A modern, syntactic sugar over constructor functions, introduced in ES6 (2015), for creating objects with a cleaner syntax.
extends and super.class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log(`Hello, my name is ${this.name}`);
}
}
const person1 = new Person("Eva", 26);
person1.greet(); // "Hello, my name is Eva"
Creates an object with a specified prototype, allowing custom inheritance from another object.
const personProto = {
greet: function() {
console.log(`Hello, my name is ${this.name}`);
}
};
const person = Object.create(personProto);
person.name = "Frank";
person.greet(); // "Hello, my name is Frank"
| Method | Syntax Example | Key Use Case |
|---|---|---|
| Object Literal | const obj = {} | Simple objects, single-use |
new Object() | const obj = new Object() | Dynamic object creation |
| Constructor Function | function Person(){} | Multiple similar objects |
| ES6 Class | class Person {} | Object-oriented, reusable, clean syntax |
Object.create() | Object.create(proto) | Prototype-based inheritance |
Β