首页 > Web开发 > 详细

js 返回 undefined 值的情况

时间:2014-02-14 01:58:53      阅读:317      评论:0      收藏:0      [点我收藏+]
  • 来源 [三生石上] 翻译的JavaScript 秘密花园 (http://bonsaiden.github.io/JavaScript-Garden/zh/#core.undefined)
  • 访问声明,但是没有初始化的变量
    1
    2
    var aaa;
    console.log(aaa); // undefined
  • 访问不存在的属性
    1
    2
    var aaa = {};
    console.log(aaa.c);
  • 访问函数的参数没有被显式的传递值
    1
    2
    3
    (function (b){
        console.log(b); // undefined
    })();
  • 访问任何被设置为 undefined 值的变量
    1
    2
    var aaa = undefined;
    console.log(aaa); // undefined
  • 没有定义 return 的函数隐式返回

    1
    2
    function aaa(){}
    console.log(aaa()); // undefined

  • 函数 return 没有显式的返回任何内容

    1
    2
    3
    4
    function aaa(){
        return;
    }
    console.log(aaa()); // undefined

js 返回 undefined 值的情况

原文:http://www.cnblogs.com/maiyan/p/3548223.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!