var a ;
if(typeof(a)==="undefined"){
//a为undefined类型
}
a = 123;
if(typeof(a)==="number"){
//a为number类型
}
a={};
if(typeof(a)==="object"){
//a为object类型
}
a="abc";
if(typeof(a)==="string"){
//a为string类型
}
a=true;
if(typeof(a)==="boolean"){
//a为boolean类型
}
a=function(){};
if(typeof(a)==="function"){
//a为function类型
}
a=[];
if(typeof(a)==="object"){
//值为数组的时候,typeof返回也是"object"
}
要判断值是否为数组,可以通过instanceof方法,判断一个值是否为另一个值的实例
a=[];
if(a instanceof Array){
//a为数组
}
js判断未定义、数字、字符串等
最新推荐文章于 2022-12-26 08:37:53 发布