What is Object Constructor in Javascript
In this article, we will discuss what is object constructor in javascript and how to create an object using constructor.
What is an object constructor?
Object constructor is a constructor function of a built-in object called an object.
Object constructor is convenient to create a single object.
Creating a new object using object() constructor:
Syntax:
var objectName= new Object();
New keyword:
- Creates a new empty object
- Sets the value of implicit prototype “__proto__” of a new empty object to tits constructor prototype.
- Calls its constructor function with “newly created memory location address” with “list of arguments” if passed.
- Returns the reference of new object, if constructor function does not return anything explicitly.
Example code:
var rect1= new Object();
In the above example code, we have created an object using an object constructor. First, we put the “var” keyword then give an object name called “ret1, and then put isequalto (=) operator to create a new object().