运行如下代码就可以看清楚:
<html>
<script language="javascript">
var msg
="使用未声明的变量undef_x: ";
if(typeof(undef_x)=="undefined")msg+="undefined ";
else msg+="defined ";

msg
+="\n";
msg
+="声明变量后未赋值undef_null_x: ";
var undef_null_x;
if(typeof(undef_null_x)=="undefined")msg+="undefined ";else msg+="defined ";
if(undef_null_x==null)msg+="null ";else msg+="not null";

msg
+="\n";
msg
+="变量赋值null null_x: ";
var null_x
=null;
if(typeof(null_x)=="undefined")msg+="undefined ";else msg+="defined ";
if(null_x==null)msg+="null ";else msg+="not null";

msg
+="\n";
msg
+="变量赋\"\"值 x: ";
var x
="";
if(typeof(x)=="undefined")msg+="undefined ";else msg+="defined ";
if(x==null)msg+="null ";else msg+="not null";

alert(msg);
</script>
</html>
运行结果为:
posted on 2007-02-26 09:30  今夜太冷  阅读(1205)  评论(0)    收藏  举报