当函数的 typeof 是 运行 时,它 returns "function" 作为类型。为什么不是 return "object"?

When typeof is run on a function, it returns "function" as the type. Why doesn't it return "object"?

Javascript 中的一个函数是一个对象。

当 运行 typeof 函数时,为什么它 return 值 "function" 而不是 "object"?

var objLit = {}
console.log(typeof objLit); // "object"

function hello() {
  console.log("hello world");
}
console.log(typeof hello); // "function"

因为规范就是这么做的。尽管所有函数都是对象,但在函数上使用 typeof 时将 return 'function' 而不是 'object'。见 table:

Type of val                            Result:
Object (does not implement [[Call]])   "object"
Object (implements [[Call]])           "function"

(函数有内部方法 [[Call]];非函数没有。)