typeof
typeof
无法准确检测数组、对象等数据类型
var a = new Date();
var b = ['1','2'];
var c = {name:'LLT', age:'15'};
var d = null;
var e = undefined;
var f = 'llt';
var g = 12345;
var h = false;
console.log(typeof a); //object
console.log(typeof b); //object
console.log(typeof c); //object
console.log(typeof d); //object
console.log(typeof e); //undefined
console.log(typeof f); //string
console.log(typeof g); //number
console.log(typeof h); //boolean
Object.prototype.toString.call()
var a = new Date();
var b = ['1','2'];
var c = {name:'LLT', age:'15'};
var d = null;
var e = undefined;
var f = 'llt';
var g = 12345;
var h = false;
console.log(Object.prototype.toString.call(a)); //[object Date]
console.log(Object.prototype.toString.call(b)); //[object Array]
console.log(Object.prototype.toString.call(c)); //[object Object]
console.log(Object.prototype.toString.call(d)); //[object Null]
console.log(Object.prototype.toString.call(e)); //[object Undefined]
console.log(Object.prototype.toString.call(f)); //[object String]
console.log(Object.prototype.toString.call(g)); //[object Number]
console.log(Object.prototype.toString.call(h)); //[object Boolean]