JavaScript中的undefined,null,NaN(Not A Number)和typeof区别
JavaScript中的类型分为:undefined,null,number,string,boolean,function和其他Object引用类型。
undefined,null,NaN(Not A Number)和typeof
undefined:表示一个对象没有被定义、或没有被初始化、或一个并不存在的对象属性。
null:表示无值。
typeof运算符返回的是一个字符串。
<script><!--function f1(){document.write('test function <br/>');}function f2(){document.write('test function2 <br/>');return;}alert(f1());//等价于:alert(typeof f1());输出undefinedalert(f2());//等价于:alert(typeof f2());输出undefined//--></script>