js有6种数据类型,包括5种基本类型 null、undefined、boolean、number、string,和1种复杂类型object(function、array都属于object)
而object、function、array也被称为引用类型
以下是可能值的列表(注意都是小写)
类型 结果
Undefined "undefined"
Null "null"
Boolean "boolean"
Number "number"
String "string"
Symbol(ECMAScript6新增) "symbol"
函数对象 "function"
任何其他对象 "object"
(包括正则、set、map等)
宿主对象(由JS环境提供) Implementation-dependent
备注:另外,值得注意的是typeof是操作符而不是函数,所以 typeof a和typeof(a) 都是符合语法的。
--------------------------------------------------------------------------------------
常见问题
typeof "1111" 为object
typeof new String("1111") 为string
typeof Object为function
Object为构造函数
typeof NaN 为number
NaN是一种特殊的number,NaN与任何值都不相等,与自己也不相等。