标签:code java eof array str typeof uncaught 技术 object
var a =1 // "number"
var b ="" // "string"
var c =true // "boolean"
var d = null // "object"
var e // "undefined"
var s = Symbol() // "symbol"
// 注意
null == undefined // true
null == {} // false
undefined == {} //false
var o = {"a":1} // "object"
typeof
typeof null // "object"
typeof [] // "object"
typeof {} // "object"
instanceof
不能检测 null
undefined
// object
({}) instanceof Object // true
//null
null instanceof Object // false
//array
[] instanceof Array // true
//error
null instanceof Null
VM1344:1 Uncaught ReferenceError: Null is not defined
at <anonymous>:1:17
(anonymous) @ VM1344:1
undefined instanceof Undefined
VM1366:1 Uncaught ReferenceError: Undefined is not defined
at <anonymous>:1:22
Object.protorype.toSting.call() 最靠谱,最常用
Object.prototype.toString.call("fd") // "[object String]"
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({}) // "[object Object]"
标签:code java eof array str typeof uncaught 技术 object
原文地址:https://www.cnblogs.com/rosendolu/p/10739488.html