
function getType(a) {
var res = typeof a;
if(res === 'string') {
alert('String');
}else if(res === 'number') {
alert('number');
}else if(res === 'object') {
res = ObjectprototypetoStringcall(a)toLowerCase();
if(resindexOf('function') !== -1) {
alert('Function');
}else if(resindexOf('array') !== -1) {
alert('Array');
}else if(resindexOf('null') !== -1) {
alert('Null');
}else if(resindexOf('undefined') !== -1) {
alert('Undefined');
}else {
alert('object');
}
}
}
使用方法getType('ss')
在ES5的时候,我们认知的数据类型确实是 6种:Number、String、Boolean、undefined、object、Null。
ES6 中新增了一种 Symbol 。这种类型的对象永不相等,即始创建的时候传入相同的值,可以解决属性名冲突的问题,做为标记。
谷歌67版本中还出现了一种 bigInt。是指安全存储、 *** 作大整数。(但是很多人不把这个做为一个类型)。
JS数据类型:JS 的数据类型有几种?8种。
JS数据类型:Object 中包含了哪几种类型?
JS数据类型:JS的基本类型和引用类型有哪些呢?
判断js中的数据类型有一下几种方法:typeof、instanceof、 constructor、 prototype、 $type()/jquerytype(),接下来主要比较一下这几种方法的异同。
1、最常见的判断方法:typeof:
2、判断已知对象类型的方法: instanceof:
3、根据对象的constructor判断: constructor:
4、通用但很繁琐的方法: prototype:
5、无敌万能的方法:jquerytype():
通常情况下用typeof 判断就可以了,遇到预知Object类型的情况可以选用instanceof或constructor方法,实在没辙就使用$type()方法。
以上就是关于如何判断js中的数据类型全部的内容,包括:如何判断js中的数据类型、JS数据类型 8种、如何判断js中的数据类型等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)