Search⌘ K

Object Instances

Explore how to create and manage object instances in JavaScript by using constructor functions. Understand how the new keyword instantiates unique objects with individual properties, enabling you to write modular and scalable code in your OOP projects.

Let’s discuss how to create objects using the constructor function.

Javascript (babel-node)
function Employee(_name, _age, _designation){
this.name = _name
this.age = _age
this.designation = _designation
}

Creating an Object Instance

Every time a new object is created, it is referred to as a new instance. Multiple object instances can be generated using constructor functions.

Syntax

Let’s take a look at the syntax for creating an object:

Javascript (babel-node)
var ObjectName = new ConstructorFunction(argument1, argument2,....)

Explanation

  • The keyword new is used to create a new object.

  • That is followed by the constructor function being called with the required arguments passed into it. This is ...