<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luigi Cruz</title>
    <description>The latest articles on DEV Community by Luigi Cruz (@luigircruz).</description>
    <link>https://dev.to/luigircruz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F385172%2Febc15a14-6226-473f-9bcd-6ff84a4d48bb.jpeg</url>
      <title>DEV Community: Luigi Cruz</title>
      <link>https://dev.to/luigircruz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/luigircruz"/>
    <language>en</language>
    <item>
      <title>JavaScript Execution Context</title>
      <dc:creator>Luigi Cruz</dc:creator>
      <pubDate>Sun, 25 Apr 2021 03:32:45 +0000</pubDate>
      <link>https://dev.to/luigircruz/javascript-execution-context-38cn</link>
      <guid>https://dev.to/luigircruz/javascript-execution-context-38cn</guid>
      <description>&lt;blockquote&gt;It is important to view knowledge as sort of a semantic tree — make sure you understand the fundamental principles, ie the trunk and big branches, before you get into the leaves/details or there is nothing for them to hang on to.
 — &lt;cite&gt;Elon Musk on &lt;a href="https://www.reddit.com/r/IAmA/comments/2rgsan/i_am_elon_musk_ceocto_of_a_rocket_company_ama/cnfre0a/" rel="noopener noreferrer"&gt;reddit&lt;/a&gt;&lt;/cite&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article we will take a look at the most important concept or the fundamental principle of the JavaScript language, that is the Execution Context. The reason for that is because if you have a good understanding of the JavaScript Execution Context, you'll have a much easier time understanding some more advanced topics like hoisting, scopes, scope chains, and closures.&lt;/p&gt;

&lt;p&gt;Now with that in mind let's dive right into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Execution Context
&lt;/h2&gt;

&lt;p&gt;Execution context is an abstract concept of an environment where the JavaScript code is executed. You can think of the execution context as a large container that can be used to hold or load things in and process. Within the large container are other smaller containers. Now the question you might ask is, who manages those containers?&lt;/p&gt;

&lt;h2&gt;
  
  
  The JavaScript Engine
&lt;/h2&gt;

&lt;p&gt;The thing that is responsible for managing the JavaScript execution context is the JavaScript Engine. Each browser has its version of the JavaScript engine. Chrome uses &lt;a href="https://v8.dev/" rel="noopener noreferrer"&gt;V8 Engine&lt;/a&gt;, Firefox uses &lt;a href="https://spidermonkey.dev/" rel="noopener noreferrer"&gt;SpiderMonkey&lt;/a&gt;, and Safari uses &lt;a href="https://trac.webkit.org/wiki/JavaScriptCore" rel="noopener noreferrer"&gt;JavaScriptCore&lt;/a&gt;. The first thing the JS engine does is it downloads the JS source code. Once the code is received, it runs into a parser and creates an &lt;a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree" rel="noopener noreferrer"&gt;Abstract Syntax Tree (AST)&lt;/a&gt; — a tree-like representation of JS code. After that, it then enters into a global execution context by default. And each invocation or calls to a function on the JS code from this point on will result in the creation of a new local execution context. Every execution context has 2 phases which we will take a look at later in this article. The JS engine also manages the memory allocation (heap memory), garbage collection (Orinoco), code conversion to bytecode (V8 Ignition), and optimization to machine code (V8 TurboFan). The JS engine is another topic of its own so we won't cover that in this article. &lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Execution Context
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Global Execution Context (The large container) &lt;/li&gt;
&lt;li&gt;Local/Function Execution Context (The small container)&lt;/li&gt;
&lt;li&gt;Eval Function Execution Context (The small container)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Global Execution Context
&lt;/h4&gt;

&lt;p&gt;This is the default execution context that the JS engine enters after it loads and parses the JS code. Once the JS engine is inside the global execution context it will create two properties in the global memory by default, the &lt;code&gt;window&lt;/code&gt; object (in the case of browsers) and the &lt;code&gt;this&lt;/code&gt; object. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;window&lt;/code&gt; object points to or is wired to the &lt;code&gt;global&lt;/code&gt; object — an object that is always created before the JS engine enters the global execution context which has properties and methods such as localStorage, innerWidth, event handlers, etc.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;this&lt;/code&gt; object (in the global execution context) is an object that points to or is wired to the &lt;code&gt;window&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;So, what will happen if there are variables and functions declared in the JS code? What it will do is it will scan through all the code and look for every variable and function declarations (variables and functions that are not nested to any other function) and store it in the global memory together with &lt;code&gt;window&lt;/code&gt; and &lt;code&gt;this&lt;/code&gt; objects.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Global Memory&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;window&lt;/td&gt;
&lt;td&gt;&amp;lt; ref. to Global Obj. &amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;this&lt;/td&gt;
&lt;td&gt;&amp;lt; ref. to window Obj. &amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;var_identifier&lt;/td&gt;
&lt;td&gt;var_value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;fn_identifier&lt;/td&gt;
&lt;td&gt;&amp;lt; fn Obj. &amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;NOTE: The function object is the snapshot of the whole function stored in the memory.&lt;/p&gt;

&lt;h4&gt;
  
  
  Local/Function Execution Context
&lt;/h4&gt;

&lt;p&gt;Every time a function is called or invoked, a brand new execution context is created for that function. Every function has its local execution context which is created once the JS engine encounters a function call. Inside the local execution context, the JS engine will create an &lt;code&gt;arguments&lt;/code&gt; object and a &lt;code&gt;this&lt;/code&gt; object by default.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;arguments&lt;/code&gt; object contains a key:value pair of parameters expected inside a function. It also contains a default property called &lt;code&gt;length&lt;/code&gt;, that counts the numbers of parameters for that function. The &lt;code&gt;arguments&lt;/code&gt; object defaults to &lt;code&gt;{ length: 0 }&lt;/code&gt; when the function's argument is empty. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;this&lt;/code&gt; object inside the function execution context varies depending on how the function is called. If it is called by an object reference, then the value of &lt;code&gt;this&lt;/code&gt; is set to that object. Otherwise, the value of &lt;code&gt;this&lt;/code&gt; is set to the &lt;code&gt;window&lt;/code&gt; object or will be of value "undefined" (in strict mode).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Local Memory&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;arguments&lt;/td&gt;
&lt;td&gt;{ length: 0 }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;this&lt;/td&gt;
&lt;td&gt;&amp;lt; ref. to window Obj. &amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;var_identifier&lt;/td&gt;
&lt;td&gt;var_value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;fn_identifier&lt;/td&gt;
&lt;td&gt;&amp;lt; fn Obj. &amp;gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Eval Function Execution Context
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;eval&lt;/code&gt; function is a dangerous function. Whenever the JS engine encounters an &lt;code&gt;eval()&lt;/code&gt; function, an execution context is created and is pushed into the call stack. It accepts a string as a parameter and evaluates it. So if you accidentally passed a malicious code in its argument, or a malicious party exploits this part of your code, then your website could potentially be severely damaged. It is not recommended to use this function as there are better alternatives to it. You can learn more about &lt;code&gt;eval&lt;/code&gt; function &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does the JS engine know the currently running Execution Context?
&lt;/h2&gt;

&lt;p&gt;JavaScript is a single-threaded language which means that it can only run a single task at a time. An example of a task is declaring a variable, assigning a value to a variable, or calling a function. We already know that a function call sets up a local/function execution context. Under the hood when the JS engine encounters a function call its task is to push that execution context into memory and pops it off when the code inside of it is done. That memory is called the &lt;strong&gt;Execution Stack&lt;/strong&gt; also known as the &lt;strong&gt;&lt;em&gt;"Call Stack"&lt;/em&gt;&lt;/strong&gt;. It is an array of execution contexts that uses a LIFO (Last In First Out) data structure. It is used by the JS engine to keep track of execution context by storing each call into the memory. The global execution context is present by default in the call stack and it is at the bottom of the stack. While executing the global execution context code, if the JS engine finds a function call, it creates a local execution context for that function and pushes it to the top of the call stack. The JS engine then executes the function whose execution context is at the top of the call stack. Once all the code of the function is executed, JS engine takes out that function execution context and start’s executing the function which is below it.&lt;/p&gt;

&lt;p&gt;Let us try to understand that with an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Initially I am inside the global execution context.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Heyyow!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am inside the first function execution context&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;second&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am again inside the first function execution context&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;second&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am inside the second function execution context&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am back at the global execution context.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fluigicruz.dev%2Fstatic%2Fimages%2F2021%2Fexecution-context%2Fcall-stack.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fluigicruz.dev%2Fstatic%2Fimages%2F2021%2Fexecution-context%2Fcall-stack.gif" alt="Call stack process"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;View a PDF copy of the Call stack process &lt;a href="https://luigicruz.dev/static/pdf/call-stack.pdf" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once the JS engine is done loading and parsing the JS code, it will set up a &lt;code&gt;global()&lt;/code&gt; execution context and pushes it to the call stack. When it sees the function call &lt;code&gt;first()&lt;/code&gt;, it will set up a new function execution context for that function and pushes it to the top of the call stack. When the JS engine encounters the function call &lt;code&gt;second()&lt;/code&gt; inside the first execution context, it will create another execution context for that function and pushes it to the top of the call stack. Once the &lt;strong&gt;&lt;em&gt;second()&lt;/em&gt;&lt;/strong&gt; function finishes, its execution context is popped off from the call stack, and the control is transferred to its parent execution context &lt;strong&gt;&lt;em&gt;first()&lt;/em&gt;&lt;/strong&gt;. When the first execution context is finished, its execution context is removed from the call stack, and the control is transferred to its parent execution context &lt;strong&gt;&lt;em&gt;global()&lt;/em&gt;&lt;/strong&gt;. Once all the code is executed, the JS engine removes the global execution context from the call stack and exits.&lt;/p&gt;

&lt;h2&gt;
  
  
  What exactly happens inside an Execution Context?
&lt;/h2&gt;

&lt;p&gt;Now that we already know that the JS engine uses the call stack to keep track of the currently running execution context, let us now understand what exactly is happening inside an execution context.&lt;/p&gt;

&lt;p&gt;The execution context has two phases: 1) the &lt;strong&gt;Creation Phase&lt;/strong&gt; and 2) the &lt;strong&gt;Execution Phase&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creation Phase
&lt;/h2&gt;

&lt;p&gt;This is the stage that the JS engine enters after the JS code is loaded and has been parsed. Every execution context has a Creation Phase. The creation of an execution context is part of the creation phase. Two &lt;a href="https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts" rel="noopener noreferrer"&gt;state components&lt;/a&gt; are created during the creation phase:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lexical Environment&lt;/strong&gt;, and&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Variable Environment&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Conceptually, the execution context is represented as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;GlobalExecutionContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;LexicalEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;VariableEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;strong&gt;Lexical Environment&lt;/strong&gt; component is a structure that defines the association of identifiers to the values of variables and functions based upon the lexical nesting structure of JS code. This association of identifier to the values of variables and functions is called &lt;code&gt;binding&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Variable Environment&lt;/strong&gt; component is also a &lt;strong&gt;Lexical Environment&lt;/strong&gt; that defines the association of identifiers to the values of variables but not functions.&lt;/p&gt;

&lt;p&gt;The difference between the two is in the variable that the identifier is bounded. The &lt;em&gt;Lexical Environment&lt;/em&gt; is used to store bindings of an identifier to the values of the variables (&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;) and functions, while the &lt;em&gt;Variable Environment&lt;/em&gt; is used to store bindings of an identifier to the values of the variable (&lt;code&gt;var&lt;/code&gt;) only.&lt;/p&gt;

&lt;p&gt;I'm confused. What is exactly inside the Lexical Environment?&lt;/p&gt;

&lt;h3&gt;
  
  
  Environment Record
&lt;/h3&gt;

&lt;p&gt;Each &lt;em&gt;Lexical Environment&lt;/em&gt; has an &lt;a href="https://tc39.es/ecma262/#sec-environment-records" rel="noopener noreferrer"&gt;Environment Record&lt;/a&gt;. The &lt;em&gt;Environment Record&lt;/em&gt; records the identifier bindings that are created within the scope of the lexical environment. Each time a JS code is evaluated (var/func declarations or assignments), a new Environment Record is created to record the identifier bindings that are created by that code. This environment in JavaScript is called the &lt;code&gt;scope&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Every &lt;strong&gt;Environment Record&lt;/strong&gt; has an &lt;strong&gt;[[OuterEnv]]&lt;/strong&gt; field, which is either &lt;em&gt;null&lt;/em&gt; or a reference to an outer Environment Record. The reason why a child function has access to its parent's scope is because of the outer environment object. For example, when the JS engine sees a variable inside a function, it will try to find the variable's value from the current function's environment record (local memory). If it could not find the variable inside of it, it will look into the outer scope (its parent environment record) up to the global scope until it finds that variable. This lookup process is called the &lt;code&gt;scope chain&lt;/code&gt;. We'll try to take a look at the scope chain and dig deeper in future articles.&lt;/p&gt;

&lt;p&gt;There are three type subclasses inside of the Environment Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://tc39.es/ecma262/#sec-declarative-environment-records" rel="noopener noreferrer"&gt;Declarative Environment Record&lt;/a&gt; — As its name suggests stores variables, classes, modules, and/or function declarations. A declarative Environment Record binds the set of identifiers defined by the declarations contained within its scope.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tc39.es/ecma262/#sec-object-environment-records" rel="noopener noreferrer"&gt;Object Environment Record&lt;/a&gt; — This environment record in the global execution context contains the bindings for all built-in globals. This is the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window" rel="noopener noreferrer"&gt;window object&lt;/a&gt; that references the &lt;a href="https://tc39.es/ecma262/#sec-global-object" rel="noopener noreferrer"&gt;global object&lt;/a&gt;. Variables and functions that are of global scope are added to the global execution context's object environment record that is why you can access global variables such as &lt;em&gt;&lt;code&gt;window.localStorage&lt;/code&gt;&lt;/em&gt; and &lt;em&gt;&lt;code&gt;window.var_name&lt;/code&gt;&lt;/em&gt;. In the local/function execution context the object environment record is composed of the &lt;code&gt;arguments&lt;/code&gt; object and the &lt;code&gt;this&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tc39.es/ecma262/#sec-global-environment-records" rel="noopener noreferrer"&gt;Global Environment Record&lt;/a&gt; — A global Environment Record is logically a single record but it is specified as a composite encapsulating an &lt;strong&gt;&lt;em&gt;object Environment Record&lt;/em&gt;&lt;/strong&gt; and a &lt;strong&gt;&lt;em&gt;declarative Environment Record&lt;/em&gt;&lt;/strong&gt;. It does not have an outer environment; it's &lt;strong&gt;[[OuterEnv]]&lt;/strong&gt; is null. It may be prepopulated with identifier bindings and it includes an associated global object whose properties provide some of the global environment's identifier bindings. As JS code is executed, additional properties may be added to the global object and the initial properties may be modified.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let us conceptually visualize the execution context inside the &lt;strong&gt;Creation Phase&lt;/strong&gt;. Take a look at this JS code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luigi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; says &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that when I say &lt;strong&gt;&lt;em&gt;conceptually&lt;/em&gt;&lt;/strong&gt;, it means that the pseudocode below is not the concrete representation of the environment the JS engine creates, but only to learn the concept by trying to visualize it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;GlobalExecutionContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;LexicalEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;EnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;DeclarativeEnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;uninitialized&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; says &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="c1"&gt;// Bindings of identifier to variables (`let` and `const`) and identifier to function objects&lt;/span&gt;
      &lt;span class="na"&gt;ObjectEnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;Global&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;this&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;OuterEnv&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// ref. to parent env. record (null in here since global has no parent execution context)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; 
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;VariableEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;EnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;DeclarativeEnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="c1"&gt;// Bindings of identifier to variables (`var`)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's try to go through each step of what's happening inside the &lt;strong&gt;Creation Phase&lt;/strong&gt; using the code snippet above:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The JS engine enters the Creation Phase.&lt;/li&gt;
&lt;li&gt;Creates a global execution context and pushes it into the call stack.&lt;/li&gt;
&lt;li&gt;Create bindings for the &lt;strong&gt;window object&lt;/strong&gt; to the &lt;strong&gt;Global object&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Create bindings for the &lt;strong&gt;this object&lt;/strong&gt; to the &lt;strong&gt;window object&lt;/strong&gt;. Note that &lt;strong&gt;this object&lt;/strong&gt; binding will vary depending on how the function is called and on &lt;em&gt;strict mode&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;global memory&lt;/em&gt; and initializes it with a value of &lt;code&gt;undefined&lt;/code&gt;. This process is called &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting" rel="noopener noreferrer"&gt;hoisting&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;strong&gt;&lt;em&gt;input&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;global memory&lt;/em&gt; without initializing it or no initial value set.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;code&gt;broadcast&lt;/code&gt; in the &lt;em&gt;global memory&lt;/em&gt; and store the whole function definition of the broadcast function in it. This function is also hoisted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next, we'll talk about how does the JS code gets executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution Phase
&lt;/h2&gt;

&lt;p&gt;This is the stage that the JS engine enters after all variables and functions are declared and necessary objects have bounded. Every execution context has an Execution Phase. Few things are happening inside this phase, the variable binding initializations, variable assignments, mutability and immutability checking, variable binding deletions, function call execution, etc.&lt;/p&gt;

&lt;p&gt;Let's try to understand that by continuing the steps we wrote from the Creation Phase:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The JS engine enters the Creation Phase.&lt;/li&gt;
&lt;li&gt;Creates a global execution context and pushes it into the call stack.&lt;/li&gt;
&lt;li&gt;Create bindings for the &lt;strong&gt;window object&lt;/strong&gt; to the &lt;strong&gt;Global object&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Create bindings for the &lt;strong&gt;this object&lt;/strong&gt; to the &lt;strong&gt;window object&lt;/strong&gt;. Note that &lt;strong&gt;this object&lt;/strong&gt; binding will vary depending on how the function is called and on &lt;em&gt;strict mode&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;global memory&lt;/em&gt; and initializes it with a value of &lt;code&gt;undefined&lt;/code&gt;. This process is called &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting" rel="noopener noreferrer"&gt;hoisting&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;strong&gt;&lt;em&gt;input&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;global memory&lt;/em&gt; without initializing it or no initial value set.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;code&gt;broadcast&lt;/code&gt; in the &lt;em&gt;global memory&lt;/em&gt; and store the whole function definition of the broadcast function in it. This function is also hoisted.&lt;/li&gt;
&lt;li&gt;The JS engine enters the Execution Phase.&lt;/li&gt;
&lt;li&gt;Take the value of variable &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt; and bind that value to the identifier inside the memory.&lt;/li&gt;
&lt;li&gt;Take the value of variable &lt;strong&gt;&lt;em&gt;input&lt;/em&gt;&lt;/strong&gt; and bind that value to the identifier inside the memory.&lt;/li&gt;
&lt;li&gt;Encounters a console log method, immediately evaluate the arguments inside it.&lt;/li&gt;
&lt;li&gt;Sees a function call named &lt;code&gt;broadcast&lt;/code&gt;, immediately creates a new local execution context for that function, and pushes it into the top of the call stack.&lt;/li&gt;
&lt;li&gt;Enters the Creation Phase of the broadcast function execution context.&lt;/li&gt;
&lt;li&gt;Creates &lt;strong&gt;arguments object&lt;/strong&gt;, in the function's &lt;em&gt;local memory&lt;/em&gt; with an initial value of &lt;code&gt;{ length: 0 }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add the passed parameter &lt;strong&gt;&lt;em&gt;message&lt;/em&gt;&lt;/strong&gt; to the first index of the arguments object.&lt;/li&gt;
&lt;li&gt;Creates an identifier &lt;strong&gt;&lt;em&gt;message&lt;/em&gt;&lt;/strong&gt; in the function's &lt;em&gt;local memory&lt;/em&gt; and store the value that is passed to the function call's argument.&lt;/li&gt;
&lt;li&gt;Goes inside the function block and evaluates the return statement.&lt;/li&gt;
&lt;li&gt;Sees a variable &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt;, it then performs a lookup of that variable inside the function's &lt;em&gt;local memory&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;It couldn't find the identifier &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;local memory&lt;/em&gt; so it then continues to look for it from its parent scope (&lt;em&gt;global memory&lt;/em&gt;). &lt;/li&gt;
&lt;li&gt;It finds the identifier &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;global memory&lt;/em&gt; so it takes that value and swap it to the variable reference.&lt;/li&gt;
&lt;li&gt;Sees a variable &lt;strong&gt;&lt;em&gt;message&lt;/em&gt;&lt;/strong&gt;, it then performs a lookup of that variable inside the function's &lt;em&gt;local memory&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;It finds the identifier &lt;strong&gt;&lt;em&gt;message&lt;/em&gt;&lt;/strong&gt; in the &lt;em&gt;local memory&lt;/em&gt; so it takes that value and swaps it to the variable reference.&lt;/li&gt;
&lt;li&gt;Returns the evaluated result of the broadcast function execution context and is popped off from the call stack.&lt;/li&gt;
&lt;li&gt;Pass the control to its calling context (the global execution context) with the returned result.&lt;/li&gt;
&lt;li&gt;Displays &lt;code&gt;Luigi says Hello, World!&lt;/code&gt; in the console.&lt;/li&gt;
&lt;li&gt;Global execution context is popped off from the call stack and then the JS engine exits.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Whew, that's a lot! There's a lot more that is happening inside the Execution Phase like object mutability and immutability checking, etc... but I tried to simplify the steps so that I won't complicate the main idea in this article. But if you wanted to dig more though, you can read through at those from the &lt;a href="https://tc39.es/ecma262/#sec-executable-code-and-execution-contexts" rel="noopener noreferrer"&gt;JavaScript Spec&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So with all of that here's an updated pseudocode for all the execution context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;GlobalExecutionContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;LexicalEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;EnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;DeclarativeEnvironmentRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;broadcast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;LocalExecutionContext&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;LexicalEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="na"&gt;EnvironmentRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;DeclarativeEnvironmentRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;ObjectEnvironmentRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                  &lt;span class="na"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
                  &lt;span class="nl"&gt;this&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
              &lt;span class="p"&gt;},&lt;/span&gt;
              &lt;span class="na"&gt;OuterEnv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;LexicalEnvironment&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;GlobalExecutionContext&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;ObjectEnvironmentRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;Global&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;this&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="nx"&gt;Obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;OuterEnv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;VariableEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;EnvironmentRecord&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;DeclarativeEnvironmentRecord&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luigi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To further explain the whole concept, I've created a high-level representation of the step-by-step process of the Execution Context using a GIF below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fluigicruz.dev%2Fstatic%2Fimages%2F2021%2Fexecution-context%2Fexecution-context.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fluigicruz.dev%2Fstatic%2Fimages%2F2021%2Fexecution-context%2Fexecution-context.gif" alt="Step by step execution process of JavaScript source code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;View a PDF copy of the Execution context process &lt;a href="https://luigicruz.dev/static/pdf/execution-context.pdf" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are few interesting topics that we didn't try to dive into deeper in this article. These are the &lt;code&gt;this object&lt;/code&gt;, &lt;code&gt;scope chain&lt;/code&gt;, &lt;code&gt;hoisting&lt;/code&gt;, &lt;code&gt;garbage collection&lt;/code&gt;, etc. We'll try to discuss those in future articles. &lt;/p&gt;

&lt;p&gt;I know that's a lot of things to absorb. You'll probably have to revisit this post multiple times to understand. While you don't need to learn all these concepts to be a good JavaScript developer, having a decent understanding of the above concepts will help you clear out those fogs at the more advanced topics. As Elon Musk said, focus on understanding the fundamental principles of things first, and later on you'll be surprised by the topic that you thought doesn't make sense — actually, isn't so hard at all.&lt;/p&gt;

&lt;p&gt;Anyways, that's all I could share. I'll see you in my next post!&lt;/p&gt;

</description>
      <category>executioncontext</category>
      <category>javascript</category>
      <category>es6</category>
    </item>
  </channel>
</rss>
