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__
2 Answers 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).
6 Comments
Function(). That's why I was confused. So why Function() evaluates to an anonymous function?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.typeof(Function()) is function but it acts like an object?Function() is an object of type function right? @JLRisheIt's true because both of them return null :)
Object.prototype.__proto__ === Object().__proto__.__proto__
1 Comment
Array.prototype.__proto__ === Array().__proto__.__proto__ . These do not evaluates to nullExplore related questions
See similar questions with these tags.