JS判断 函数是否定义/变量是否定义

函数是否定义:

<script type="text/javascript">
try {
if(typeof FunName === "function") { //FunName为函数名称
alert("is function");
} else {
alert("not a function");

}
} catch(e) {}
</script>
 

变量是否定义:

<script type="text/javascript">
try {
if(typeof myvalue==="undefined") { //myvalue为变量名称
alert("is value");
} else {
alert("not a value");

}
} catch(e) {}
</script>
 

posted @ 2020-03-22 11:45  程序员宝典  阅读(1134)  评论(0编辑  收藏  举报