1)
Boolean expressionAn expression that evaluates to either true or false. Non-Boolean expressions are converted to Boolean values, when necessary, according to the following rules: All objects are considered true. 
Strings are considered false if and only if they are empty. 
null and undefined are considered false. 
Numbers are considered false if and only if they are zero. 2)
As JScript is loosely typed, a single variable can hold different types of data over the course of a script.

解决方案 »

  1.   

    if (typeof(var) != "undefined") {
    }也是用typeof(var)
      

  2.   

    typeof Operator
    Returns a string that identifies the data type of an expression.typeof[(]expression[)] ;The expression argument is any expression for which type information is sought. Res
    The typeof operator returns type information as a string. There are six possible values that typeof returns: "number," "string," "boolean," "object," "function," and "undefined."
      

  3.   

    js无需判断变量类型
    <script>
    var abc=false;
    if(abc){
    }
    alert()
    </script>
      

  4.   

    js中变量不用声明就可以使用,当然了这样很不好!
    判断是否被声明:
    if(typeOf(a) == "undefined") {
      alert("未定义");
    }使用typeOf(变量名)可以获得变量的类型。
      

  5.   

    不行啊。我刚在IE5.01下测试。使用typeOf还是有问题。
      

  6.   

    <script>
    var abc;
    function test(name){
    try{eval(name);return true}catch(e){return false};
    }
    alert(test("abc"))
    alert(test("def"))
    </script>
      

  7.   

    if(typeof(a) == "undefined") 
    {
      alert("error:");
    }
    typeof 不是 typeOf
      

  8.   

    对于if (typeof(a) == "undefined")这样其实并不能判断一个变量是否有定义,只能判断一个变量是否有值,因为当你只对变量定义而不赋值时这个变量的值也是undefined!如:var a;