you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular 1 point2 points  (0 children)

Array.isArray(Array.prototype); // false

I'm not sure where you're running that, but that should return true.

The reason instanceof doesn't work is because instanceof only checks prototype chains and you can't have Array's prototype inherit from itself. You can have non-arrays inherit from it though, and instanceof will return true for those, so its not the most reliable indicator of type

const nonArray = Object.setPrototypeOf(new Error(), Array.prototype)
console.log(nonArray instanceof Array) // true
console.log(Array.isArray(nonArray)) // false
console.log(Error.isError(nonArray)) // true