How to Make Object in JavaScript?

Object literal: `const obj = { name: “John”, age: 30 };`

`new Object()`: `const obj = new Object();`

Constructor function: `function Person(name) { this.name = name; } const obj = new Person(“John”);`

`Object.create()`: `const obj = Object.create(null);`

Class: `class Person { constructor(name) { this.name = name; } } const obj = new Person(“John”);`

Add properties after creation: `const obj = {}; obj.name = “John”; obj.age = 30;`

Using computed property names: `const key = “name”; const obj = { [key]: “John” };`

Suggested for You

Trending Today