数据类型检测

111 阅读1分钟

数据类型检测

typeof

console.log(typeof typeof [])  //'string'

上述代码考察了typeof的特性,一定返回字符串!

console.log(typeof null) // 'object'
  • null 空指针对象
  • Function.prototype.call
  • typeof 实现call的对象【函数、箭头函数、生成器函数、构造函数】 ->'function'
  • typeof 剩下未实现call的对象 ->'object' 原理: ECMAScript提供的内置类型在计算机底层都是按照二进制数据存储的,以对应的数字开始代表不同类型
    1:数字 010:浮点型
    100:字符串
    110:布尔
    -2^30:undefined
    000000:null
    000:对象

instanceof

constructor

Object.prototype.toString.call