Creating an object using a constructor function in JavaScript
☰Fullscreen
Table of Content:
// Creating an object using a constructor function function Person(firstName, lastName, age) { this.firstName = firstName; this.lastName = lastName; this.age = age; this.greet = function() { console.log("Hello, " + this.firstName + " " + this.lastName); }; } var person = new Person("Rumman", "Ansari", 26);
Mastering JavaScript: From Fundamentals to Advanced Concepts