undefined 是指变量未赋任何类型的值
null      变量是一个空的 object

解决方案 »

  1.   

    那undefined与null一般情况下可以通用么?
      

  2.   

    Null Data Type
    The null data type has only one value in JScript: null. The null keyword cannot be used as the name of a function or variable.A variable that contains null contains "no value" or "no object." In other words, it holds no valid number, string, Boolean, array, or object. You can erase the contents of a variable (without deleting the variable) by assigning it the null value.Notice that in JScript, null is not the same as 0 (as it is in C and C++). Also note that the typeof operator in JScript will report null values as being of type Object, not of type null. This potentially confusing behavior is for backwards compatibility.Undefined Data Type
    The undefined value is returned when you use: an object property that does not exist, 
    a variable that has been declared, but has never had a value assigned to it. 
    Notice that you cannot test to see if a variable exists by comparing it to undefined, although you can check if its type is "undefined". In the following code example, assume that the programmer is trying to test if the variable x has been declared:// This method will not work
    if (x == undefined)
        // do something// This method also won't work - you must check for
    // the string "undefined"
    if (typeof(x) == undefined)
        // do something// This method will work
    if (typeof(x) == "undefined")
        // do something
    Consider comparing the undefined value to null.someObject.prop == null;
    This comparison is true, if the property someObject.prop contains the value null, 
    if the property someObject.prop does not exist. 
    To check if an object property exists, you can use the new in operator:if ("prop" in someObject)
        // someObject has the property 'prop'