> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter1/12javascript-quan-gong-lve-ff1a-ke-fu-js-de-qi-guai-bu-fen/121zhi-xing-huan-jing-yu-ci-hui-huan-jing/1217han-shu-3001-huan-jing-yu-bian-shu-huan-jing.md).

# 1.2.1.7.函數、環境與變數環境

* 變數環境 (viable environment)
  * 變數所在的位置
  * 執行下面程式碼

    ```
    function b() {
     var myVar;
     console.log(myVar);
    }

    function a() {
      var myVar = 2;
     console.log(myVar);
      b();
    }

    var myVar = 1;
    console.log(myVar);
    a();
    ```
  * 會看到
    * 1
    * 2
    * undefined
  * 解析
    * 此程式將會建立對應的執行堆為
    * 每個Execution context的記憶體都是各自獨立不相關聯的

      ![](/files/-M4M0McqlUnmgR3EYJBX)
