typeof (Array, null) 返回对象,typeof(null, Array) 返回函数

typeof (Array, null) returns object and typeof(null, Array) returns function

本文关键字:返回 typeof null Array 函数 对象      更新时间:2023-09-26

正如标题所说明的那样,typeof (Array, null)返回objecttypeof(null, Array)返回function

它返回第二个参数的类型。

为什么?

因为

  • typeof 是一个运算符,而不是一个函数,所以typeof(expr)typeof expr的,首先计算expr
  • a,b返回b

所以

typeof (a, b)返回typeof b

在您的情况下

  • typeof (Array, null) typeof null这是"object"
  • typeof(null, Array)typeof ArrayArray是一个函数。