Js类型相关总结

  • Js的基本数据类型
number、boolean、string、undefined、null、Symbol(Es6新加)
  • 复杂数据类型
Object

类型检测

  1. typeof 检测
    检测原理是根据变量存储时低位
typeof 'test' //string
typeof 1 //number
typeof true //boolean
typeof undefined //undefined
typeof null //object feature
typeof Symbol() //symbol
typeof new Function //function
  1. instanceof检测
    L instanceof R,原理R.prototype是否在L的原型链中

3.Object.prototype.toString.call

Object.prototype.toString.call([]) //"[object Array]"
Object.prototype.toString.call({}) //"[object Object]"
Object.prototype.toString.call(1) //"[object Number]"
Object.prototype.toString.call(true) //"[object Boolean]"
Object.prototype.toString.call(null) //"[object Null]"
Object.prototype.toString.call(undefined) //"[object Undefined]"
Object.prototype.toString.call(Symbol()) //"[object Symbol]"
Object.prototype.toString.call(Function) //"[object Function]"

数组检测

1.Array.isArray()
2.[] instanceof Array
3.Object.prototype.toString.call([])

数字检测

isNaN()

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容