- undefined
typeof undefined
// 'undefined'
- string
typeof ''
//'string'
- number
typeof 1
//'number'
- boolean
typeof true
//'boolean'
- object
typeof {}
typeof []
typeof null
//'object'
- function
typeof function(){}
'function'
总结:
- typeof 以全部小写字符串返回类型
- 可以区分除了
null
以外的基本类型- 引用类型只能区分
function
,不能区分数组与对象