> For the complete documentation index, see [llms.txt](https://1425816423.gitbook.io/my-knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://1425816423.gitbook.io/my-knowledge-base/qian-duan-ji-shu/shen-ru-li-jie-javascript-xi-lie/zhi-xing-shang-xia-wen.md).

# 执行上下文

tags: 深入理解JavaScript summary: 本文从ECMAScript标注规范的角度讲解了JavaScript中的执行上下文，包括全局执行上下文、函数执行上下文和eval执行上下文。 Created time: December 25, 2022 11:39 AM emoji: <https://tc39.es/ecma262/img/favicon.ico> readerNumber: 6

* 本文参考自[ECMAScript6规范](https://262.ecma-international.org/6.0/#sec-execution-contexts)

执行上下文是一种规范，用于跟踪ECMAScript实现对代码的运行时评估。**在任何时间点，最多有一个执行上下文实际执行代码。这称为运行时执行上下文(*****running*****&#x20;execution context)**。堆栈用于跟踪执行上下文。正在运行的执行上下文始终是该堆栈的顶部元素。每当控制从与当前运行的执行上下文关联的可执行代码转移到与该执行上下文无关的可执行代码时，就会创建一个新的执行上下文。新创建的执行上下文被推送到堆栈上，并成为正在运行的执行上下文。

执行上下文纯粹是一种规范机制，不需要对应于ECMAScript实现的任何特定构件。ECMAScript代码不可能直接访问或观察执行上下文。

未完待续。
