Objects using constructor
by REPLY2SAGAR
JavaScript
function Person(firstName, lastName, age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.isAdult = function() {
return this.age >= 18;
};
}
// Creating an instance of Person
const alice = new Person("Sagar", "Salunke", 25);
console.log(alice.isAdult()); // Outputs: true
console.log(alice.firstName); // Outputs: Alice