<?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: Logeshwaran</title>
    <description>The latest articles on DEV Community by Logeshwaran (@thelogeshwaran).</description>
    <link>https://dev.to/thelogeshwaran</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%2F524943%2F223088f8-7da7-4e88-a6fc-68e79333ea1a.jpg</url>
      <title>DEV Community: Logeshwaran</title>
      <link>https://dev.to/thelogeshwaran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thelogeshwaran"/>
    <language>en</language>
    <item>
      <title>Javascript Hoisting</title>
      <dc:creator>Logeshwaran</dc:creator>
      <pubDate>Mon, 08 Mar 2021 13:50:40 +0000</pubDate>
      <link>https://dev.to/thelogeshwaran/javascript-hoisting-5ak8</link>
      <guid>https://dev.to/thelogeshwaran/javascript-hoisting-5ak8</guid>
      <description>&lt;p&gt;Are you confused about javascript hoisting?&lt;br&gt;
Don't worry! From this blog, your confusion will go away and you will get a clear idea about javascript hoisting. So.......let's start!&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Javascript Hoisting?
&lt;/h3&gt;

&lt;p&gt;Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. But...but ..Technically this will not happen. &lt;/p&gt;

&lt;p&gt;Whenever any javascript code is executed Global Execution context&lt;br&gt;
(If you don't know, &lt;a href="https://dev.to/thelogeshwaran/understanding-global-execution-context-and-execution-context-scope-2nc"&gt;read this&lt;/a&gt;) is created.&lt;br&gt;
It has two phases one is the Creation phase and the other one is the Execution phase.&lt;/p&gt;

&lt;p&gt;The variables and functions are put into memory before the execution phase. This will help us to use a function or a variable before it is declared. This behavior is known as Hoisting.&lt;/p&gt;

&lt;p&gt;Let me show you what is happening...&lt;/p&gt;
&lt;h3&gt;
  
  
  Hoisting in variables
&lt;/h3&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;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;//Declaration &lt;/span&gt;
  &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;//Initialization&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;//Prints 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the above code, first variable a is declared and then initialized and it is used.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;//Initialization&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;//Declaration &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What will you think the above code will print? It will print an error?&lt;br&gt;
No, it prints the value of a. How it prints the value of a. Let me show using the global execution context.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JI_E6iVA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2554tgh71oh5w5il7ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JI_E6iVA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2554tgh71oh5w5il7ly.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above diagram shows that the global execution context is created, in that two phases are there(Creation phase and Execution phase).&lt;/p&gt;

&lt;p&gt;In the creation phase code is not executed, only the memory is allocated. So, the javascript will allocate memory for each function and variable. This is how for variable a memory is allocated and undefined assigned.&lt;/p&gt;

&lt;p&gt;In the Execution phase, the javascript will run the code line by line. So, it will assign the value 5 for the variable a and then prints the value(shown below). Because the line initialization line  comes before the console.log.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wz3snkW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k09sez8o7zzfwgbzsqjc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wz3snkW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k09sez8o7zzfwgbzsqjc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, before executing the code the javascript will allocate memory for all variables. Due to this behavior, we can able to access the variable without an error. (If you still don't understand &lt;a href="https://dev.to/thelogeshwaran/understanding-global-execution-context-and-execution-context-scope-2nc"&gt;read this&lt;/a&gt;).&lt;/p&gt;
&lt;h4&gt;
  
  
  Only Declarations are hoisted
&lt;/h4&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//prints undefined&lt;/span&gt;
    &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// Initialization&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// Declaration&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//Prints 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Why the first console.log print undefined not 5? Is Hoisting is not working? &lt;/p&gt;

&lt;p&gt;No, hoisting is happening. Only Declarations are hoisted not initialization. It means in the creation phase only memory is allocated, values are not assigned. In the execution phase, values are assigned, until that it is undefined. In the execution phase until the second line(a =5) value of the variable a, is undefined. After the second line, the values are assigned to the variable. So, it prints the value 5 in the last line.&lt;/p&gt;
&lt;h3&gt;
  
  
  Function Hoisting
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;y&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;The above code works perfectly fine. Because in the creation phase the javascript copies the function code to the add variable(shown below), instead of assigning undefined like variables.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NykEx-4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/visxso4xh9qht2mf1ex3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NykEx-4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/visxso4xh9qht2mf1ex3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above diagram shows that in the creation phase the javascript assigns undefined for variables, but....for functions, it assigns the code. So, in the execution phase wherever the function is called it give the code, and do the work.&lt;/p&gt;
&lt;h4&gt;
  
  
  Functions expressions are not hoisted
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;//Prints “TypeError : add is not a function”&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;y&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;If you execute the code, it will show the following result.&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="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;TypeError&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look into Global execution for the above code, &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O_uXeDOQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni345ecxpxogyflnkg0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O_uXeDOQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni345ecxpxogyflnkg0t.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here add is considered as a variable and assigned undefined value.&lt;br&gt;
So, if you call it as a function it will produce a TypeError.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;So, we have learned that when you run the code, the Global Execution context is created. In that, there are two phases, which is the Creation phase and the Execution phase. In the creation phase, for variables memory is allocated and for function, code is copied. Due to this behavior, we can able to access the variable before it is declared.&lt;br&gt;
This is known as "Hoisting in Javascript".&lt;/p&gt;

&lt;p&gt;Thank you for reading the article. If you like it please share it with your friends. If you have any questions, feel free to ask in the comments. &lt;/p&gt;

&lt;p&gt;Happy Coding!!😀&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>career</category>
    </item>
    <item>
      <title>Understanding Global Execution Context and Execution Context Stack</title>
      <dc:creator>Logeshwaran</dc:creator>
      <pubDate>Wed, 03 Mar 2021 15:07:11 +0000</pubDate>
      <link>https://dev.to/thelogeshwaran/understanding-global-execution-context-and-execution-context-scope-2nc</link>
      <guid>https://dev.to/thelogeshwaran/understanding-global-execution-context-and-execution-context-scope-2nc</guid>
      <description>&lt;p&gt;This blog will help you understand javascript better, here you will learn about &lt;em&gt;Execution context&lt;/em&gt; and &lt;em&gt;Execution context stack&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution context(EC)
&lt;/h2&gt;

&lt;p&gt;It is like an environment where javascript code is evaluated and executed. Whenever any code in javascript is executed, it is run in &lt;em&gt;Execution context&lt;/em&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Execution context
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            1. Global Execution context 
            2. Functional Execution context
            3. Eval function Execution context.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Global Execution context
&lt;/h4&gt;

&lt;p&gt;This is the default execution context. The global code, (i.e the code which is not in the function and object) is executed in it.&lt;br&gt;
Since javascript is single-threaded, only one execution context is possible.&lt;/p&gt;
&lt;h4&gt;
  
  
  Function Execution context
&lt;/h4&gt;

&lt;p&gt;The code inside the function is executed here. Multiple execution contexts are possible because there will be chances of having multiple functions inside one program.&lt;/p&gt;
&lt;h4&gt;
  
  
  Eval function Execution context
&lt;/h4&gt;

&lt;p&gt;The code inside the eval function is executed here. This is the rare function used by developers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Execution Context stack
&lt;/h2&gt;

&lt;p&gt;It is used to store the execution contexts. Whenever the javascript code starts its execution global execution context is created and the execution context stack is created &lt;em&gt;(Calling stack)&lt;/em&gt;. It works based on 'Last in, first out'.&lt;br&gt;&lt;br&gt;
 When the javascript engine starts executing the javascript code &lt;em&gt;global execution context&lt;/em&gt; is created and pushed on the top of the call stack. When it reaches a function in a code, the functional execution context is created and pushed on the top of the stack. &lt;/p&gt;

&lt;p&gt;It looks kinda overwhelming, right?. Let me explain with a simple program and diagrams.&lt;/p&gt;

&lt;p&gt;Let's take a small 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="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;Hello&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="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;First&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="c1"&gt;//Second function is called here.&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="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;Second&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="c1"&gt;//first function is called here.&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;End&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;When the JS engine starts executing, the global execution context is created and pushed to the top of the call stack.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2f407dnh59v474hag4r.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2f407dnh59v474hag4r.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After it prints Hello, it starts executing line by line. When the JS reaches the line(shown below), the first function is pushed to the top of the call stack and starts executed.&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="nf"&gt;first&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8269nr9nrvbv1fhsafq.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8269nr9nrvbv1fhsafq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After pushing to the call stack, It starts executing the first function line by line. So, it prints &lt;em&gt;"first"&lt;/em&gt; and there is the second function is called. When the JS engine reaches the line(shown below), the second function is called and it is pushed into the call stack.&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="nf"&gt;second&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsujapbpy82m8i32f5low.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsujapbpy82m8i32f5low.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second function starts executed and prints "second". After that inside the second function, there is nothing to execute. After completing the execution of the second function, it is popped out of the stack. This is called "Last in, first-out". After that, there is nothing to execute in the first function. So, it is popped out of the call stack. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furf5zhbbb4pzkxkqiy36.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Furf5zhbbb4pzkxkqiy36.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After executing all the code, the global execution context is popped out of the call stack. This is how the execution context stack is created.&lt;/p&gt;

&lt;p&gt;Now, let's talk about the Execution context. It has two phases,&lt;br&gt;
 1.Creation phase &lt;br&gt;
 2.Execution phase&lt;/p&gt;
&lt;h3&gt;
  
  
  Creation phase
&lt;/h3&gt;

&lt;p&gt;In this phase the JS engine scan through the code, it allocates memory for all variables and functions. For variables, it will allocate memory and assign an undefined. It will not execute any code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Execution phase
&lt;/h3&gt;

&lt;p&gt;In this phase, the JS engine starts executing the code line by line. It assigns values to the variable and executes the function calls.&lt;/p&gt;

&lt;p&gt;Let's take some example 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;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&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;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;num2&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&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="nx"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the creation phase, the variables are stored "key: value" pairs(shown in the diagram). Now the code is not executed, just memory is allocated, for the variables it allocates undefined, and for function, it just copied the code. Along with this, it creates a global object (i.e window in the browsers) and creates &lt;em&gt;this&lt;/em&gt; binding object, which points global object.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhkg9y9wmieclm081eqh.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhkg9y9wmieclm081eqh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it starts executing the code line by line, in execution code, the values are assigned to a variable(shown below). When it reaches the function add another execution context is created. It is called a functional execution context. In that also two phases are there, creation and execution. Inside that creation phase, memory is allocated for the variables with the value of undefined(shown below).&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28bx1upx65jm5o5osgfe.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28bx1upx65jm5o5osgfe.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that execution starts and values are assigned and execution start (i.e values are added and stored in the result). The below diagram shows that function is executed and stored.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwnfnztbuvr7mjkpogl2.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwnfnztbuvr7mjkpogl2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, it returns the value and stores it in the addition variable.&lt;br&gt;
Now the add function is popped out of the stack.(shown below)&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8raul1x0aj4qx3mo64hw.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8raul1x0aj4qx3mo64hw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After printing the variable the global execution context is popped out of the call stack.&lt;/p&gt;

&lt;p&gt;That’s it and if you found this article helpful please hit the like  button and feel free to comment below! I’d be happy to talk 😃.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>understanding</category>
    </item>
    <item>
      <title>How to write good commit messages?</title>
      <dc:creator>Logeshwaran</dc:creator>
      <pubDate>Thu, 03 Dec 2020 18:50:26 +0000</pubDate>
      <link>https://dev.to/thelogeshwaran/how-to-write-good-commit-messages-714</link>
      <guid>https://dev.to/thelogeshwaran/how-to-write-good-commit-messages-714</guid>
      <description>&lt;h1&gt;
  
  
  What is a &lt;code&gt;commit&lt;/code&gt; message?
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;commit&lt;/code&gt; command is used to save changes to our local repository after staging in Git. Before saving to our local repository, we need to tell Git which changes you need to save, as you have done lots of changes. A better way to do this, by adding commit messages to tell what changes you have done.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why do we need to write good commit messages?
&lt;/h1&gt;

&lt;p&gt;If the project history is seen only by you, you can write whatever you want. But, when multiple people are involving in that project, you have to write good commit messages. So that they could able to understand better. Roughly said, the commit is the comment of each change, what and why you have made the change.&lt;/p&gt;

&lt;p&gt;Commit messages frequently communicate why such a change was made, so it helps to understand better. Thus better understanding and collaboration make work more efficient.&lt;/p&gt;

&lt;p&gt;There are three important points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To speed up the review process &lt;/li&gt;
&lt;li&gt;To help the developer team to write good release notes.&lt;/li&gt;
&lt;li&gt;To help the future maintainers(Why such feature was added).&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  How to write good commit messages?
&lt;/h1&gt;

&lt;p&gt;There are no strict definitions for good commit messages, but generic rules have emerged. A commit message should have only one logical change. &lt;/p&gt;

&lt;p&gt;There are several conventions used by different developer teams and companies. If you work in a particular company, you have to follow their conventions.&lt;/p&gt;

&lt;p&gt;Good commit messages are not only good for others with who you may be collaborating but also for you, when you look back on your history you can able to understand much better.&lt;/p&gt;

&lt;p&gt;The general format is :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Short (72 chars or less) summary of changes&lt;/p&gt;

&lt;p&gt;More details explanatory text. wrap it to 72 characters. The blank &lt;br&gt;
line separating the summary from the body is critical(unless you &lt;br&gt;
omit the body entirely).&lt;/p&gt;

&lt;p&gt;Write you commit message in the imperative: "Fix bug " and not "Fixed bug" or "Fixes bug".This convention matches up with commit messages generated by commands like git merge and git revert.&lt;br&gt;
Further paragraphs come after blank lines.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bullet points are okay, too.&lt;/li&gt;
&lt;li&gt;Typically a hyphen or asterisk is used for the bullet, followed &amp;gt;by a single space. Use a hanging indent.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Rules for a great git commit message style
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Separate subject from body with a blank line&lt;/li&gt;
&lt;li&gt;Do not end the subject line with a period&lt;/li&gt;
&lt;li&gt;Capitalize the subject line and each paragraph&lt;/li&gt;
&lt;li&gt;Use the imperative mood in the subject line&lt;/li&gt;
&lt;li&gt;Wrap lines at 72 characters&lt;/li&gt;
&lt;li&gt;Use the body to explain what and why you have done something. In 
most cases, you can leave out details about how a change has 
been made.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can make yours good too, this is the format I used to :&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;type&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;subject&lt;/span&gt;

   &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1.TYPE
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;feat: The new feature you're adding to a particular application&lt;/li&gt;
&lt;li&gt;fix: A bug fix&lt;/li&gt;
&lt;li&gt;style: Feature and updates related to styling&lt;/li&gt;
&lt;li&gt;refactor: Refactoring a specific section of the codebase&lt;/li&gt;
&lt;li&gt;test: Everything related to testing&lt;/li&gt;
&lt;li&gt;docs: Everything related to documentation&lt;/li&gt;
&lt;li&gt;chore: Regular code maintenance.[ You can also use emojis to 
represent commit types]&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2.Subject
&lt;/h2&gt;

&lt;p&gt;This is a short description of the changes you have made. It should start with a Capital letter and should not exceed more than 50 characters. Eg: Add x filter instead of Added x filter or Adds x filter.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.Body
&lt;/h2&gt;

&lt;p&gt;It is used to explain what changes you have made and why you have made the changes. Not all commit messages need a body, it's optional.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips&lt;/strong&gt;: If you have several logics and you if you feel difficult to commit message split up and do it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How not to do it:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Don't do the end-of-day commits, it looks messy when you go through the history it looks messy, and others cannot able to understand.&lt;/li&gt;
&lt;li&gt;Don't do lazy commits, it's really hard for others to understand what is going in the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Want to learn more about git:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://try.github.io/"&gt;https://try.github.io/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2"&gt;https://git-scm.com/book/en/v2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
