Prototype Objects

This lesson explains prototype objects, what they are, how they are accessed, and why they are used to add properties.

In this lesson, we will learn about the major concept of “Prototype Objects” in JavaScript.

Before we get into how it can be used, let’s discuss what a prototype is.

Prototype Properties in Objects

Instead of jumping directly into the definition, let’s begin by looking at the code below:

Press + to interact
//creating an constructor function named EmployeeConstructor
function EmployeeConstructor(_name,_age,_designation) {
this.name = _name,
this.age = _age,
this.designation = _designation
}
//creating an object from EmployeeConstructor using "new" keyword
//The object created is stored in the variable employeeObj
var employeeObj = new EmployeeConstructor('Joe',22,'Developer')
console.log(employeeObj)

As seen above, if we display employeeObj, the three properties, name, age and designation are displayed along with their values, encapsulated within the EmployeeConstructor object, which was created using new.

If the same code is run locally on the browser, the browser console will display the following:

Notice anything different? Apart from age, designation and ...