标签:instanceof object Object 数据类型 var test true
typeof
用在基本数据类型和函数时,返回其对应类型的描述,对于引用类型都返回为object.instanceof
无法判断基本数据类型,对于引用类型数据,返回其其对应类型。Object.prototype.toString
无论基本数据类型还是引用类型返回其对应类型。
对应测试结果如下:
typeof test |
instanceof |
Object.prototype.toString.call(test) |
|
var test = 'xuriliang'; | string | test instanceof String //false |
[object String] |
var test = 27; | number | test instanceof Number //false |
[object Number] |
var test = true; | boolean | test instanceof Boolean //false |
[object Boolean] |
var test = [1,2,3]; | object | test instanceof Array //true |
[object Array] |
test instanceof Object //true |
|||
var test = null; | object | test instanceof Object //false |
[object Null] |
var test = undefined; | undefined | test instanceof Object //false |
[object Undefined] |
var test = new String('xuriliang') | object | test instanceof String //true |
[object String] |
test instanceof Object //true |
|||
var test = new Number(27) | object | test instanceof Number //true |
[object Number] |
test instanceof Object //true |
|||
var test = new Boolean(true) | object | test instanceof Boolean //true |
[object Boolean] |
test instanceof Object //true |
|||
var test = new Array(1,2,3) | object | test instanceof Array //true |
[object Array] |
test instanceof Object //true |
|||
var test = function(){} | function | test instanceof Function //true |
[object Function] |
test instanceof Object //true |
|||
var test = /d/ | object | test instanceof RegExp //true |
[object RegExp] |
test instanceof Object //true |
标签:instanceof,object,Object,数据类型,var,test,true 来源: https://www.cnblogs.com/zy-simpleboy/p/14790955.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。