JS : Difference between Object and Object.constructor

63 views Asked by At

I don't understand the difference between Object and Object.constructor.

Let's take an example :

function Person() {}
var p = new Person();

Person is the function to create objects. So :

p instanceof Person //true
p.constructor // Person

Person is the constructor and I can create persons with new Person()

But Object is also a constructor ( I can create object with new Object()). So why Object has a constructor property since it's already a constructor itself ?

Thanks

2

There are 2 answers

0
Bergi On BEST ANSWER

So why does it have a constructor property since it's already a constructor itself?

Because every constructor is a function, and those inherit their properties (like the call, apply and bind methods) from Function.prototype. Including the Function.prototype.constructor property, which points to Function.

0
adz5A On

constructor is a pointer towards the constructor function used to create a given value, all objects have one. For primitives it points towards the primitive constructor: Object, Number, Function and so on.

Doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor