<?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>Forem: jerry enebeli</title>
    <description>The latest articles on Forem by jerry enebeli (@jerryenebeli).</description>
    <link>https://forem.com/jerryenebeli</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%2F377839%2Fbc3bb6c7-1924-49ad-95f0-111eb24238a4.png</url>
      <title>Forem: jerry enebeli</title>
      <link>https://forem.com/jerryenebeli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jerryenebeli"/>
    <language>en</language>
    <item>
      <title>Understanding Call Stacks In Java Script</title>
      <dc:creator>jerry enebeli</dc:creator>
      <pubDate>Sat, 16 May 2020 11:14:58 +0000</pubDate>
      <link>https://forem.com/jerryenebeli/understanding-call-stacks-in-java-script-54e6</link>
      <guid>https://forem.com/jerryenebeli/understanding-call-stacks-in-java-script-54e6</guid>
      <description>&lt;h2&gt;
  
  
  What is a call stack?
&lt;/h2&gt;

&lt;p&gt;A call stack is a region in memory that keeps track of the running/active subroutine/function in a program. it follows a first in last out approach(FILO). When a function is called it is pushed on top of the call stack and when it returns it is popped out of the call stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Global execution context?
&lt;/h2&gt;

&lt;p&gt;A global execution context is always the first function on the stack. it is an anonymous function the creates the environment in which the javascript code runs. For an environment like the browser the global execution context creates a global object called windows and assigns it to "this".&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack limits and overflow
&lt;/h2&gt;

&lt;p&gt;As interesting as stacks sounds they also have a memory limit just like any storage. the limit of the stack determines the total number of functions that can be on the stack at once. Stack limits differ in various browsers. when a stack limit is exceeded it causes an error known as stack overflow.&lt;/p&gt;

&lt;p&gt;The quickest way to cause a stack overflow is by recursion.&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;function&lt;/span&gt; &lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will cause a stack overflow because it keeps adding to the stack and exceed the given stack memory allocation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript has only one call stack
&lt;/h2&gt;

&lt;p&gt;Javascript is a single-threaded language and what this means for the call stack is javascript can only have one call stack.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>callstack</category>
      <category>memory</category>
      <category>v8</category>
    </item>
  </channel>
</rss>
