- typeof:
*可以判断: undefined/数值/字符串/布尔值/function
*不能凯断: null与object object 与array - instanceof: 判断对象的具体类型
- ===:可以判断: undefined, null
var a;
console.log(a, typeof a, typeof a === 'undefined', a === undefined);
console.log(undefined === 'undefined');
a = 4;
console.log(typeof a === 'number');
a = 'sxl';
console.log(typeof a === 'string');
a = true;
console.log(typeof a === 'boolean');
a = null;
console.log(typeof a, a === null);
console.log('--------------');
var b1 = {
b2: [1, 'abc', console.log],
b3: function() {
console.log('b3');
return function() {
}
}
}
console.log(b1 instanceof Object, b1 instanceof Array);
console.log(b1.b2 instanceof Array, b1.b2 instanceof Object);
console.log(b1.b3 instanceof Function, b1.b3 instanceof Object);
console.log(typeof b1.b3 === 'function');
console.log(typeof b1.b2[2] === 'function');
b1.b2[2](4)
console.log(b1.b3()());