首页 > Web开发 > 详细

js变量类型判断 严格通用 Object.prototype.toString.call()

时间:2018-11-21 17:14:20      阅读:155      评论:0      收藏:0      [点我收藏+]

Object.prototype.toString.call()判断结果:

Object.prototype.toString.call(true)
"[object Boolean]"
Object.prototype.toString.call(1)
"[object Number]"
Object.prototype.toString.call(null)
"[object Null]"
Object.prototype.toString.call(undefined)
"[object Undefined]"
Object.prototype.toString.call(‘ndefined‘)
"[object String]"
Object.prototype.toString.call([])
"[object Array]"
Object.prototype.toString.call({})
"[object Object]"
Object.prototype.toString.call(alert)
"[object Function]"

typeof判断结果:

typeof undefined
"undefined"
typeof true
"boolean"
typeof 1
"number"
typeof ‘sds‘
"string"
typeof alert
"function"
typeof null
"object"
typeof []
"object"
typeof {}
"object"

特别的:(typeof)

var a = new String(‘123‘);
console.log(a);
console.log(Object.prototype.toString.call(a));
console.log(typeof a);

结果为:

String {"123"}
[object String]
object

js变量类型判断 严格通用 Object.prototype.toString.call()

原文:https://www.cnblogs.com/ysk123/p/9996034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!