之前coding过程中,一个计算之后的值偶尔会出现NaN,就要判断,然后用到了typeof 就简单介绍下。
一、typeof操作符返回一个字符串,
指示未经
计算的操作数的类型
二、语法 typeof value :value是一个表达式,表示对象或原始值,其类型将被返回。
三、value的类型及返回结果
类型 | 结果 |
---|---|
Undefined | "undefined" |
Null | "object" (见下方) |
Boolean | "boolean" |
Number | "number" |
String | "string" |
Symbol (ECMAScript 6 新增) | "symbol" |
宿主对象(由JS环境提供) | Implementation-dependent |
函数对象 ( [[Call]] 在ECMA-262条款中实现了) | "function" |
任何其他对象 | "object" |
typeof 123 === 'number';typeof "name" === 'string';typeof true === 'boolean';typeof Symbol() === 'symbol';typeof undefined === 'undefined';typeof [1, 2, 3] === 'object';typeof new Date() === 'object'; typeof null === 'object'; 出现其他的就要自己console一下看看是什么了