你好JS:[5]Typeof
的有关信息介绍如下:typeof在JavaScript中很常用,它可以用来判断数据类型。
可检测的数据类型:
"undefined","boolean","string","number","object","function"
检测"undefined"例子:
var t=function (){
c=0;
if(typeof c!="undefined")
{alert(typeof c!="undefined")}
}
t();
检测"boolean"例子:
var t=function (){
c=true;
if(typeof c=="boolean")
{alert("测试成功")}
}
t();
检测"string"例子:
var t=function (){
c="string";
if(typeof c=="string")
{alert("测试成功"+":"+c)}
}
t();
检测"number"例子:
var t=function (){
c=123;
if(typeof c=="number")
{alert("测试成功"+":"+c)}
}
t();
检测"object"例子:
function A(){}
var t=function (){
var c=new A();
if(typeof c=="object")
{alert("测试成功"+":"+c)}
}
t();
检测"function"例子:
function A(){}
var t=function (){
if(typeof A=="function")
{alert("测试成功"+":"+A)}
}
t();