//第一种typeof
typeof 1 // 'number'
typeof '1' // 'string'
typeof undefined // 'undefined'
typeof true // 'boolean'
typeof Symbol() // 'symbol'
typeof null // 'object'
typeof [] // 'object'
typeof {} //'object'
typeof function(){} // 'function'
//第二种Object.prototype.toString
Object.prototype.toString({}) // "[object Object]"
Object.prototype.toString.call({}) //同上结果,加上call也ok
Object.prototype.toString.call(1) // "[object Number]"
Object.prototype.toString.call('1') // "[object String]"
Object.prototype.toString.call(true) // "[object Boolean]"
Object.prototype.toString.call(function())// "[object Function]"
Object.prototype.toString.call(null) //"[object Null]"
Object.prototype.toString.call(undefined) //"[object Undefined]"
Object.prototype.toString.call(/123/g) //"[object RegExp]"
Object.prototype.toString.call(new Date()) //"[object Date]!
Object.prototype.toString.call([]) //"[object Array]"
Object.prototype.toString.call(document)//"[object HTMLDocument]"
Object.prototype.toString.call(window) //"[object Window]"
js数据类型判断
于 2022-11-24 18:33:32 首次发布
关键词由优快云通过智能技术生成