typeof 和 Object.prototype.toString.call 数据类型判断的区别
2017-03-14 17:20
801 查看
使用 typeof 来判断数据类型,只能区分基本类型,即 “number”,”string”,”undefined”,”boolean”,”object” 五种。
但 Object.prototype.toString.call 使用,可以区分7种
console.log(Object.prototype.toString.call(123)) //[object Number]
console.log(Object.prototype.toString.call('123')) //[object String]
console.log(Object.prototype.toString.call(undefined)) //[object Undefined]
console.log(Object.prototype.toString.call(true)) //[object Boolean]
console.log(Object.prototype.toString.call({})) //[object Object]
console.log(Object.prototype.toString.call([])) //[object Array]
console.log(Object.prototype.toString.call(function(){})) //[object Function]
封装
但 Object.prototype.toString.call 使用,可以区分7种
console.log(Object.prototype.toString.call(123)) //[object Number]
console.log(Object.prototype.toString.call('123')) //[object String]
console.log(Object.prototype.toString.call(undefined)) //[object Undefined]
console.log(Object.prototype.toString.call(true)) //[object Boolean]
console.log(Object.prototype.toString.call({})) //[object Object]
console.log(Object.prototype.toString.call([])) //[object Array]
console.log(Object.prototype.toString.call(function(){})) //[object Function]
封装
![](https://oscdn.geek-share.com/Uploads/Images/Content/202004/11/8e50a28bf8b71624c80000ae66f0bf10.png)
相关文章推荐
- js中精确判断对象类型--关于typeof 和Object.prototype.toString方法的区别
- js判断对象类型 typeof与Object.prototype.toString.call方法的区别
- 通过Object.prototype.toString.call()--判断数据(基本、引用)类型
- 判断js中各种数据的类型方法之 typeof() 和 Object.prototype.toString() 详解
- js中利用Object.prototype.toString.call()判断数据类型
- typeof,instanceof,Object.prototype.toString来判断数据类型
- Object.prototype.toString.call()进行类型判断
- 通过 Object.prototype.toString.call() 进行类型判断
- js 检测数据类型instanceof/constructor和 Object.prototype.toString.call()
- js instanceof、typeof、Object.prototype.toString.call(obj)的用法和区别
- js进行类型判断 Object.prototype.toString.call()
- 【JavaScript】Object.prototype.toString.call()进行类型判断
- 通过 Object.prototype.toString.call() 进行类型判断
- Object.prototype.toString.call() 进行类型判断
- 通过 Object.prototype.toString.call() 进行类型判断
- Object.prototype.toString.call()进行类型判断
- Object.prototype.toString.call()进行类型判断
- typeof、instanceof、Object.prototype.toString.call() 区分对象类型
- Object.prototype.toString.call() 区分对象类型(判断对象类型)
- 判断一个变量的类型Object.prototype.toString.call