返回值: number, string, boolean, object, undefined, function, symbol
分别返回 undefined object number
isNaN(NaN) // true
补充
补充:
typeof是 JS 中最常用的类型判断运算符之一。
- 可能的返回值(7 种):
"undefined"、"object"、"boolean"、"number"、"string"、"function"、"symbol"、"bigint"(ES2020 后)。- 三个特殊返回值:
typeof undefined === 'undefined'typeof null === 'object'(历史遗留 bug,需特殊判断)typeof NaN === 'number'(NaN 仍是 number 类型,但不代表数字)typeof不能区分数组、对象、null,更精确的判断用Array.isArray、Object.prototype.toString.call(x)。
来源整理自:vue3js.cn 面试官系列



