> For the complete documentation index, see [llms.txt](https://strctr.gitbook.io/programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://strctr.gitbook.io/programming/01-languages/javascript/01-language/a-core/a1-javascript-execution/01-execution-context.md).

# 01. Execution Context

When JS code executes, it always happens within certain *execution context*. For each of types of executable code, there’s an execution context. There are 4 types of executable code in JS:

* **Global code**,
  * Content of `<script />` elements
  * Non-module code
* **Module code**,
* * Content of `<script type="module" />`
  * Module code
* **Function code**,
  * Content of event attributes (e.g. `<p onclick="...">`)
  * Anything that’s executed directly within a function,
* **Eval code**.
  * Text that’s supplied to a built-in `eval` function is parsed as *Eval code*

As you can see, execution contexts can logically form a stack:

1. First there might be Global code or Module code with its own execution context;
2. That code might call a function, with its own execution context;
3. That function could call another function, and so on and so forth.
4. Even if function is calling itself recursively, a new execution context is being entered with every invocation.


---

# 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://strctr.gitbook.io/programming/01-languages/javascript/01-language/a-core/a1-javascript-execution/01-execution-context.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.
