> 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/1212zhi-xing-huan-jing-ff1a-chuang-zao-yu-ti-sheng.md).

# 1.2.1.2.執行環境：創造與提升

* JavaScript code不會直接執行, 而是得先經過JavaScript engine的轉換
* 執行環境的建立分為兩階段
  * 1.Execution context is created (creation phase)
    * 在記憶體中為變數和函數空出空間, 並將變數設為**undefined**
    * 建立global object, this
    * hoisting:&#x20;
      * 當syntax parser執行程式碼時, 開始設定轉化, 她會知道你在哪裡轉化變數和函數, 設定變數和函數在記憶體空間裡, 這個步驟稱為提升 (hoisting)
      * 在逐步執行程式碼前, JavaScript engine已經為變數和函數在記憶體中建立一個空間了
        * 但像是變數的宣告, 雖會為a預留空間, 但他會在執行時才會知道a是什麼值

          ```
            var a = "Hello world";
          ```
        * 若不知道是甚麼值時, 會用**undefined**來取代
          * 所有JavaScript的**變數**一開始都會被設定為**undefined**
          * 而**函數**則是一開始就設定好


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET 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/1212zhi-xing-huan-jing-ff1a-chuang-zao-yu-ti-sheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
