JS基础——数据类型判断typeof、instanceof、Object.prototype.toString
栏目: JavaScript · 发布时间: 6年前
内容简介:对应测试结果如下:
typeof 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
|
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
白帽子讲Web安全(纪念版)
吴翰清 / 电子工业出版社 / 2014-6 / 69.00元
互联网时代的数据安全与个人隐私受到前所未有的挑战,各种新奇的攻击技术层出不穷。如何才能更好地保护我们的数据?《白帽子讲Web 安全(纪念版)》将带你走进Web 安全的世界,让你了解Web 安全的方方面面。黑客不再神秘,攻击技术原来如此,小网站也能找到适合自己的安全道路。大公司如何做安全,为什么要选择这样的方案呢?在《白帽子讲Web 安全(纪念版)》中都能找到答案。详细的剖析,让你不仅能“知其然”,......一起来看看 《白帽子讲Web安全(纪念版)》 这本书的介绍吧!