Why does typeof function return “function”?

后端 未结 2 742
谎友^
谎友^ 2021-01-11 09:15

If both array and function are object subtypes, then why does typeof function return \"function\" and typeof array return \"obje

相关标签:
2条回答
  • 2021-01-11 09:50

    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.

    0 讨论(0)
  • 2021-01-11 09:52

    Because the specification defines different behaviour for typeof when it interacts with objects implementing [[Call]] (i.e. functions).

    0 讨论(0)
提交回复
热议问题