Javascript 中 null 与 undefined关系

下面结果是什么?

<html>
  <head>
    <script type="text/javascript">
        function a()
        {
        //没有返回值
        }
        alert(a());
    </script>
  </head>
  <body>
  </body>
</html>

结果: undefined

所以函数没有声明返回值,就反悔 undefined作为返回值。

 

 

null 与  undefined 的关系: undefined实际是从null派生出来的。

验证:

<html>
  <head>
    <script type="text/javascript">
    alert(null == undefined);
    </script>
  </head>
  <body>
  </body>
</html>

结果是: true

posted @ 2012-08-01 22:53  allenbackpacker  阅读(228)  评论(0编辑  收藏  举报