DEV Community

Discussion on: Three ways to create an object in JavaScript

Collapse
 
alimrandev profile image
Abdullah Al Imran • Edited

class Person {
constructor(name){
this.name = name
};
sayHello(){
return Hi ${this.name}
}
}
const person = new Person('Jon Doe');

console.log(person.sayHello()); //HI Jon Doe

You can also use the constructor function to create an object in es6.

Collapse
 
barriosdfreddy profile image
Barrios Freddy

Yeah... that's it, thank you