数据类型判断方法
1、typeof(返回值为字符串)
可以判断undefined,数值('number'),字符串('string'),布尔值('boolean'),
方法('function')
(null返回为object)
let a = undefinedlet b = 2let c = '123'let d = falselet e = function() { console.log(123); }let f = nullconsole.log('a', typeof a, 'b', typeof b, 'c', typeof c, 'd', typeof d, 'e', typeof e, 'f', typeof f, );
2、instanceof(返回值为布尔)
检测构造函数的 **prototype** 属性是否出现在某个实例对象的原型链上
用来判断对象Object、数组Array、方法Function
function demo() {}let a = new demo()console.log(a instanceof demo);console.log(a instanceof Object);
3、===(返回值为布尔)
可以判断undefined,null