js 返回 undefined 值的狀況

  • 來源 [三生石上] 翻譯的JavaScript 祕密花園 (http://bonsaiden.github.io/JavaScript-Garden/zh/#core.undefined)
  • 訪問聲明,可是沒有初始化的變量
    js var aaa; console.log(aaa); // undefined
  • 訪問不存在的屬性
    js var aaa = {}; console.log(aaa.c);
  • 訪問函數的參數沒有被顯式的傳遞值
    js (function (b){ console.log(b); // undefined })();
  • 訪問任何被設置爲 undefined 值的變量
    js var aaa = undefined; console.log(aaa); // undefined
  • 沒有定義 return 的函數隱式返回
    js function aaa(){} console.log(aaa()); // undefinedgit

  • 函數 return 沒有顯式的返回任何內容
    js function aaa(){ return; } console.log(aaa()); // undefinedgithub

相關文章
相關標籤/搜索