您的位置:首页 > 移动开发 > Objective-C

js判断Null和object object和array

2019-06-12 09:37 1961 查看
js中的数据类型一共分为两大类:基本类型和引用类型。
基本类型包括:
number:任意的数字
string:任意的字符串
boolean:true/false
null:null
undefined:undefined
引用类型:
object:任意的对象
function:一种特殊的对象可以执行
Array:一种特殊的对象(内部数据是有序的,由下标)
function和Array也都是object
判断类型的三种方法:

1.typeof可以判断undefined 、number 、string、boolean、function
不能判断 Null 和object  object 和Array(typeof:返回数据类型的字符串表达式;)
var a;
a=5;
console.log(typeof a)
a="Ss";
console.log(typeof a)
a=true;
console.log(typeof a)
a=undefined;
console.log(typeof a)
var b={
b1:[1,"2",console.log],
b2:function(){
console.log(2)
}
}
console.log(typeof b.b2)
运行结果:
检测数据类型.html:16 number
检测数据类型.html:18 string
检测数据类型.html:20 boolean
检测数据类型.html:22 undefined
检测数据类型.html:29 function
2.instanceof可以判断对象的具体类型
3.===可以判断null和undefined
a=undefined;
console.log(a===undefined)
a=null
console.log(a===null)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: