create an object in nodejs code example
Example 1: create nodejs new object
class Person {
constructor(fname, lname) {
this.firstName = fname;
this.lastName = lname;
}
}
const person = new Person('testFirstName', 'testLastName');
console.log(person.firstName); // testFirstName
console.log(person.lastName); // testLastName
Example 2: create nodejs new object
function Person(fname, lname) {
this.firstName = fname;
this.lastName = lname;
}