var xxx="s";
if(typeof(xxx)=="undefined")
alert("undefined");
else
alert(typeof(xxx));
//   var   your_var='xixi'; 
if(your_var){ 
    alert('haha'); 
}else{ 
    alert('hehe'); 

your_var不是布尔值,没报错已经不错了...

解决方案 »

  1.   

    象这样的问题你在firefox下调试一下就知道了。
      

  2.   

    没问题滴!
        <script type="text/javascript">
        <!--var your_var='xixi';if(your_var.id)
    {
        alert('haha');
    }
    else
    {
        alert('hehe');
    }alert('end');    //-->
        </script>
      

  3.   

    ¦¦--这个不是或吧,||--这么写才对!
        <script type="text/javascript">
        <!--//var your_var='xixi'; if (typeof(your_var)=="undefined" || your_var==null)
        alert("your_var is undefined");
    else 
        alert("your_var is defined");     //-->
        </script>
      

  4.   

    晕,原来是CSDN把或给替换了!
      

  5.   

    if(your_var) 这个语句只能一个对象的存不存,就是说your_var是一个对象,而不是一个无意义的单词,否则会抱错,你必须定义它,var your_var;当没给它值时他会返回underfined(等价于false),当它有值时就是true