前端最精准的判断类型

47 阅读1分钟

Object.prototype.toString.call('') [object String]

Object.prototype.toString.call({name:""}) [object Object]

Object.prototype.toString.call([]) [object Array]

Object.prototype.toString.call(true) [object Boolean]

Object.prototype.toString.call(function(){return false}) [object Function]

Object.prototype.toString.call(Symbol("111")) [object Symbol]

Object.prototype.toString.call(null) [object Null]

Object.prototype.toString.call(NaN) [object Number]

Object.prototype.toString.call(undefined) [object Undefined]