Constructor Functions

This lesson introduces constructor functions, their syntax and gives examples to explain the concept.

In the previous lesson, we discussed why the use of constructor functions is necessary, but we still don’t know what they are. Let’s delve into the details in this lesson.

Introduction

The question from previous lesson still stands, what is a better approach for creating multiple objects?

Let’s think about it.

We discussed that all the employees had all the properties in common, i.e., name, age and designation. So wouldn’t it be nice to have one generic template for the object employee which has all these properties in it and then all the objects can then just be created from it? In short, wouldn’t it be better to have a blueprint for the object employee?

The way to create an object type from a blueprint is by using constructor functions.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy