1:typeof
只能判断基本数据类型 数字,字符串、布尔 复杂数据类型都是object
1 console.log(typeof"123"); //string 2 console.log(typeof {}); //object 3 console.log(typeof []); //object
2:instanceof 主要是根据构造原型来判断的
1 const array1=new Array() 2 console.log(array1 instanceof Array); //true
3:Object.prototype.toString.call() 能准确判断数据类型
1 console.log(Object.prototype.toString.call(123));//[object Number] 2 console.log(Object.prototype.toString.call([]));//[object Array] 3 console.log(Object.prototype.toString.call({}));//[object Object] 4 console.log(Object.prototype.toString.call(null));//[object Null]
标签:判断,console,log,object,数据类型,JS,Object,toString From: https://www.cnblogs.com/tyysf/p/17089808.html