If both array and function are object subtypes, then why does typeof function
return \"function\"
and typeof array
return \"obje
Very ugly, yet correct answer: because ECMAScript specification says so. Keep in mind that on the low level, every array is basically a mere object with "length" property.
If you want to check if given object is actually an array, use Array.isArray.
Because the specification defines different behaviour for typeof
when it interacts with objects implementing [[Call]]
(i.e. functions).