0

Object is a function Object.prototype is an object whose constructor is Object itself.

But what is Object()?

can someone explain why this statement outputs true

Object.prototype.__proto__ === Object().__proto__.__proto__
asked Jan 20, 2018 at 17:31

2 Answers 2

2

But what is Object()?

Evaluating Object() produces a new empty object based on the Object prototype.

can some explain why this statement outputs true

Object.prototype.__proto__ === Object().__proto__.__proto__

Object() produces a new object which is based on the Object prototype. For an object created from a particular prototype, the __proto__ is a reference to that prototype.

Therefore, it follows that Object.prototype and Object().__proto__ both reference the same value:

console.log(Object.prototype === Object().__proto__)

Since these both refer to the same thing, it also follows that your equality expression above is true. (incidentally Object.prototype.__proto__ is null, so it would also be equal to any other null value).

answered Jan 20, 2018 at 17:37
Sign up to request clarification or add additional context in comments.

6 Comments

Not the same case with Function(). That's why I was confused. So why Function() evaluates to an anonymous function?
@GauravChaudhary Because that's what it's designed to do. I don't see any reason to assume that Function() and Object() would do the same thing, but Function() does create a value based on the Function prototype, which is analogous to what Object() does: Function().__proto__ === Function.prototype is true.
Thanks! I got it but still I would like to know typeof(Function()) is function but it acts like an object?
@GauravChaudhary In JavaScript, anything that is not a primitive is technically an object, so yes, functions are objects.
okay! So Function() is an object of type function right? @JLRishe
|
0

It's true because both of them return null :)

Object.prototype.__proto__ === Object().__proto__.__proto__
answered Jan 20, 2018 at 17:40

1 Comment

and how about this Array.prototype.__proto__ === Array().__proto__.__proto__ . These do not evaluates to null

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.