Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Array instanceof Object?

Tags:

javascript

I was playing with instanceof in javascript and I stumbled upon the following.

Array instanceof Object
returns true

Object instanceof Array
returns false

What is the relationship between Array and Object here ?

like image 256
adi rohan Avatar asked Oct 06 '14 18:10

adi rohan


1 Answers

Between the constructors, the relationship or prototype chain is:

Array -> Function.prototype -> Object.prototype
Object -> Function.prototype -> Object.prototype

The 1st is true because a constructor is a Function and functions are themselves Objects.

Array instanceof Function // true
Object instanceof Function // true

(function () {}) instanceof Object // true
like image 109
Jonathan Lonowski Avatar answered Sep 22 '22 17:09

Jonathan Lonowski