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