Creating an object using a constructor function in JavaScript

Rumman Ansari   Software Engineer   2024-09-29 08:05:15   411  Share
Subject Syllabus DetailsSubject Details Login to Open Video
☰ TContent
☰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

Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.