<?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: AmanGupta1703</title>
    <description>The latest articles on DEV Community by AmanGupta1703 (@amangupta1703).</description>
    <link>https://dev.to/amangupta1703</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%2F988066%2F43cc9c97-136f-477b-9591-d2cda845aba0.jpeg</url>
      <title>DEV Community: AmanGupta1703</title>
      <link>https://dev.to/amangupta1703</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amangupta1703"/>
    <language>en</language>
    <item>
      <title>Call Stack and Execution Context</title>
      <dc:creator>AmanGupta1703</dc:creator>
      <pubDate>Thu, 26 Jun 2025 13:33:52 +0000</pubDate>
      <link>https://dev.to/amangupta1703/call-stack-and-execution-context-250a</link>
      <guid>https://dev.to/amangupta1703/call-stack-and-execution-context-250a</guid>
      <description>&lt;h2&gt;
  
  
  What is a Callstack?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is part of the JavaScript engine.&lt;/li&gt;
&lt;li&gt;A part of the JavaScript engine that keeps track of function calls.&lt;/li&gt;
&lt;li&gt;It is a data structure that operates on a LIFO (Last-In-First-Out) basis to remove an execution context from the Call Stack.&lt;/li&gt;
&lt;li&gt;- The first item pushed to the stack is the Global Execution Context. Each time a function is invoked, a new Function Execution Context is added (pushed) on top.&lt;/li&gt;
&lt;li&gt;Once a function completes, its context is popped off the stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is an Execution Context?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is the environment in which JavaScript code is evaluated and executed.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It goes through two main phases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Creation Phase&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Execution Phase&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The engine scans the code and allocates memory for variables and functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Functions are hoisted with their full definitions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variables declared with &lt;code&gt;var&lt;/code&gt; are hoisted and initialised with &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are hoisted but remain &lt;strong&gt;uninitialized&lt;/strong&gt; — they are in the &lt;strong&gt;Temporal Dead Zone (TDZ)&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Primitive values are stored in the Call Stack; reference values (like objects) are stored in the &lt;strong&gt;Heap&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Execution Phase
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The code is executed line by line.&lt;/li&gt;
&lt;li&gt;Variables declared with &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; are assigned their actual values.&lt;/li&gt;
&lt;li&gt;Accessing a &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; variable &lt;strong&gt;before&lt;/strong&gt; its declaration results in a &lt;strong&gt;ReferenceError&lt;/strong&gt; due to the &lt;strong&gt;TDZ&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Temporal Dead Zone (TDZ)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The TDZ for a &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; variable starts at the beginning of its scope and ends when the variable is declared.&lt;/li&gt;
&lt;li&gt;Accessing the variable in this zone will throw a ReferenceError.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
