简单数据库类型: undefined null boolean number string
复杂数据类型 : object array
typeof 检测数据类型
1.简单数据类型
(1) typeof undefined ==> " undefined "
(2) typeof true / typeof false ==> " boolean "
(3) typeof 111 /typeof NaN ==> " number "
(4) typeof " 111 " ==> " string "
(5) typeof Symbol ==> " function "
(6) typeof new Function ==> " function "
(7) hello = function(){ } typeof hello ==> f(){ }
2. 复杂数据类型
(1) typeof [ ] ==> " object "
(2) typeof { } ==> " object "
(3) typeof null ==> " object "
(4) typeof new 构造函数 ==> " object "
typeof new Array() /Error() /Number() / Date() / Object() ==> " object "
instanceof 检测对象之间的关联关系
检测引用类型的值和构造函数的值是否为同一类型的
typeof可以检测到对象类型但不知道是什么类型的对象
instanceof可以弥补typeof的缺陷来检测是什么类型的对象
(1) a = new Number(111);
a instanceof Number ==> true
(2) b = new String("111")
b instanceof string ===> true
(3)" 111 " instanceof String ==> false
111 instanceof Number ==> false
typeof && instanceof 比较: