Here's the code:
var o ={};
console.log(Object.getPrototypeOf(o) == Object.prototype); // returns true as expected
console.log(Object.getPrototypeOf(Array) == Array.prototype); // returns false why?
Could someone please clarify the second result?
2 Answers 2
because Array is not an 'array' but the Prototype of Array but with this example :
var a = [];
console.log(Object.getPrototypeOf(a) == Array.prototype);
It works
answered Nov 24, 2015 at 13:31
Arnaud Gueras
2,06215 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Try
var a=[];
console.log(Object.getPrototypeOf(a) == Array.prototype);
You're using the Array type itself, instead of an instance of it.
answered Nov 24, 2015 at 13:30
JNF
3,7403 gold badges35 silver badges65 bronze badges
Comments
lang-js
Arrayis not an instantiated instance of an Array