You are currently viewing What is object constructor in javascript

What is object constructor in javascript

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:


var objectName= new Object();

New keyword:

  1. Creates a new empty object
  2. Sets the value of implicit prototype “__proto__” of a new empty object to tits constructor prototype.
  3. Calls its constructor function with “newly created memory location address” with “list of arguments” if passed.
  4. 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().

Leave a Reply