<?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: ParthParolekar</title>
    <description>The latest articles on DEV Community by ParthParolekar (@parthparolekar).</description>
    <link>https://dev.to/parthparolekar</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%2F668914%2F57779e87-ce0f-4392-9d2c-dd248a1fa176.png</url>
      <title>DEV Community: ParthParolekar</title>
      <link>https://dev.to/parthparolekar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/parthparolekar"/>
    <language>en</language>
    <item>
      <title>Week 1 of #151daysofcode</title>
      <dc:creator>ParthParolekar</dc:creator>
      <pubDate>Sat, 14 Aug 2021 18:14:44 +0000</pubDate>
      <link>https://dev.to/parthparolekar/week-1-of-151dyasofcode-hg6</link>
      <guid>https://dev.to/parthparolekar/week-1-of-151dyasofcode-hg6</guid>
      <description>&lt;p&gt;I will be writing a blog every week to share my progress in the #151daysofcode challenge. Its been 2 weeks since I started this challenge and this is the summary of first week.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day - 1/7
&lt;/h3&gt;

&lt;p&gt;I completed a basic react project that shows the user some books based on the genres they select. It uses some of the basic react features like &lt;strong&gt;useState&lt;/strong&gt; to update the state of the app depending on the genres the user selects. The genres are added dynamically so every time a book is added with a genre that is not already present, a button with that genre name is added in the app and when the user clicks that button, some books from that specific genre are displayed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/W9oA1zHhhC?amp=1"&gt;Live Project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://t.co/r7QzvcYGsY?amp=1"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Day - 2/7
&lt;/h3&gt;

&lt;p&gt;On day 2, I made an app with javascript that tells the user if their birthdate is lucky or not. The user inputs their birth-date and their lucky number. It then calculates the sum of digits in their birthdate. For example, if the birthdate is 1st January 2000, then the sum of digits will be (01/01/2000) 0+1+0+1+2+0+0+0=4.&lt;br&gt;
If the sum of digits of the birth-date is divisible by the user's lucky number, then the user's birthdate is lucky, else it is not lucky.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/hu6yUfp76q?amp=1"&gt;Live Project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://t.co/iMpYHPnWXp?amp=1"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Day - 3&amp;amp;4/7
&lt;/h3&gt;

&lt;p&gt;On day 3 and 4, I worked on an app that tells the user the minimum number of notes to be returned to the customer. It takes bill amount as the first input and cash received as the second. If the bill amount is 50 and the cash received is 100, then the amount to be returned is 50. Now the app calculates the minimum number of notes to use to return the amount. Here it will be 1 note of 50.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/WTynhVSpjP?amp=1"&gt;Live Project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://t.co/EP4TUClh3D?amp=1"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Day - 5/7
&lt;/h3&gt;

&lt;p&gt;On day 5, I made an app that checks if the user's birthdate is a palindrome or not. A palindrome is a word that spells the same backwards as well. For example "eye" is a palindrome.&lt;br&gt;
The app checks if the user's birthdate is a palindrome in 3 different formats (dd/mm/yyyy, mm/dd/yyyy, mm/dd/yy). If it is not a palindrome, the app goes on to check the next or the previous date which could have been a palindrome and calculates the number of days to that date. This was one of the hardest problems to solve as there were a lot of things to take care of and coming up with a logic was not easy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/EkBZYRHyrO?amp=1"&gt;Live Project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://t.co/jpAZCXAelz?amp=1"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 6&amp;amp;7/7
&lt;/h3&gt;

&lt;p&gt;I spent day 6 and 7 in creating an app about triangles. This app has multiple options that you can choose from. You can find the area of a triangle, check the hypotenuse of a triangle, check whether the three angles that you input make a triangle and finally you can take a simple quiz about triangles. You get 2 points for a correct answer, 0 if you skip the question and a point is deducted for every wrong answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/7lSBKMvjqo?amp=1"&gt;Live Project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://t.co/ALuJiYBkK2?amp=1"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;This was pretty much what I did in my first 7 days of the #151daysofdcode challenge. I would recommend you to take part in this challenge as it helps me to be consistent. All you have to do is code at least an hour every day and share your progress on twitter. Click on this &lt;a href="https://151daysofcode.netlify.app/"&gt;link&lt;/a&gt; if you want to participate.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>How code is executed in Javascript.</title>
      <dc:creator>ParthParolekar</dc:creator>
      <pubDate>Thu, 12 Aug 2021 05:56:47 +0000</pubDate>
      <link>https://dev.to/parthparolekar/how-code-is-executed-in-javascript-31ji</link>
      <guid>https://dev.to/parthparolekar/how-code-is-executed-in-javascript-31ji</guid>
      <description>&lt;p&gt;Welcome to my first ever blog. I am learning web development and I would like to share my learning on the internet. In this blog we will see how a javascript code is executed. I saw a &lt;a href="https://www.youtube.com/watch?v=iLWTnMzWtj4&amp;amp;list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP&amp;amp;index=3" rel="noopener noreferrer"&gt;youtube video&lt;/a&gt; explaining this same topic by Akshay Saini and I will explain it in my own words. It will help me to understand it better and also spread some knowledge along the way.&lt;/p&gt;

&lt;h1&gt;
  
  
  How code is executed in javascript
&lt;/h1&gt;

&lt;p&gt;Every time a javascript program is run, a &lt;strong&gt;Global Execution Context&lt;/strong&gt; is formed. Think of it as a container that stores all the variables, functions and executes all the code written. There are two components in the global execution context.&lt;/p&gt;

&lt;p&gt;1.) Memory component&lt;br&gt;
2.) Code component&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%2Fo54f9jker5ohkp9p9jux.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%2Fo54f9jker5ohkp9p9jux.png" alt="Global Exec Context.docx - Word"&gt;&lt;/a&gt;&lt;em&gt;Figure 1&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let us take an example code and go step by step to see how each line of code is executed.&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%2F58d5yjr2megnldwgi30j.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%2F58d5yjr2megnldwgi30j.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;Figure 2&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The javascript code is executed in two different phases.&lt;br&gt;
&lt;em&gt;Phase 1&lt;/em&gt; - &lt;strong&gt;&lt;em&gt;Memory creation phase&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Phase 2&lt;/em&gt; - &lt;strong&gt;&lt;em&gt;Code execution phase&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 1 - Memory creation phase
&lt;/h3&gt;

&lt;p&gt;In this phase, the javascript engine goes through the code written, line by line, and reserves memory for every variable and function that it encounters. The way the data is stored in the memory component is like a key-value pair. The variable name as the key and its value as its value.&lt;/p&gt;

&lt;p&gt;Let us see this happening line by line.&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%2Fvhw4fzm4inh3inhaww4f.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%2Fvhw4fzm4inh3inhaww4f.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;Figure 3&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The moment javascript encounters the 1st line (see &lt;em&gt;Figure 3&lt;/em&gt;), it reserves a memory location for that variable with its name as a key(in this case &lt;code&gt;num&lt;/code&gt;) and allocates a value to it. The allocated value is &lt;strong&gt;undefined&lt;/strong&gt; and not 3. In phase 1, the value of the variable is always stored as &lt;strong&gt;undefined&lt;/strong&gt;. Javascript does not care about the value that is assigned to that variable during the memory allocation phase. It stores the variable name as the key and &lt;strong&gt;undefined&lt;/strong&gt; as its value.&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%2Frar3sm56dh908fkdveel.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%2Frar3sm56dh908fkdveel.png" alt="Num-undefined.docx - Word"&gt;&lt;/a&gt;&lt;em&gt;Figure 4&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let us move to the second line.&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%2Ffievw6uxzso4myn3dlqg.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%2Ffievw6uxzso4myn3dlqg.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;Figure 5&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we have a function keyword on line 2. This tells javascript that here's a function declaration. Just like what happened when we declared a variable, a memory location is reserved for this particular function with the name &lt;code&gt;double&lt;/code&gt; but unlike the variable where the value is stored as &lt;strong&gt;undefined&lt;/strong&gt;, the value for the function is the code inside the curly braces "{}". Yes! The entire piece of code inside those curly braces is stored in the memory component, line by line, character by character.&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%2Fzp7o7n59t20t0r8ynnpz.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%2Fzp7o7n59t20t0r8ynnpz.png" alt="example-code"&gt;&lt;/a&gt;&lt;em&gt;Figure 6&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here's an example (&lt;em&gt;Figure 6&lt;/em&gt;) to see the values that are stored in variables and let us see what happens when we console.log &lt;code&gt;num&lt;/code&gt; and &lt;code&gt;double&lt;/code&gt;. &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%2Fh311tnfgqa08g04jso17.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%2Fh311tnfgqa08g04jso17.png" alt="example-code-answer"&gt;&lt;/a&gt;&lt;em&gt;Figure 7&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As we discussed above, the value stored in the variable &lt;code&gt;num&lt;/code&gt; is undefined and the value stored in the function &lt;code&gt;double&lt;/code&gt; is the entire code inside the curly braces{}.&lt;/p&gt;

&lt;p&gt;The variables inside the &lt;code&gt;double&lt;/code&gt; function do not get stored in the memory component like we saw with the &lt;code&gt;num&lt;/code&gt; variable on line 1. We will see what happens to them very shortly.&lt;/p&gt;

&lt;p&gt;The global execution context looks like this after completing line 2.&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%2F8p3105g1gyjda41soz2e.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%2F8p3105g1gyjda41soz2e.png" alt="Global Exec Contex 2.docx - Word"&gt;&lt;/a&gt;&lt;em&gt;Figure 8&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After the function is stored inside the memory component, javascript goes to the line after the function which is line 6 (&lt;em&gt;figure 9&lt;/em&gt;)&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%2F9ar6nxswq1wiv9dq2tf4.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%2F9ar6nxswq1wiv9dq2tf4.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure 9&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now the code encounters another variable &lt;code&gt;doubleNum&lt;/code&gt; and the same  process is followed like with the &lt;code&gt;num&lt;/code&gt; variable where the memory is reserved, the variable is stored in that memory and the assigned value is &lt;strong&gt;undefined&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The global execution context now looks like this(&lt;em&gt;figure 10&lt;/em&gt;)&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%2F5zxiid11gkodpojzrgrj.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%2F5zxiid11gkodpojzrgrj.png" alt="GEC finsihed"&gt;&lt;/a&gt;&lt;em&gt;figure 10&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This marks the end of the 1st phase which was the &lt;strong&gt;&lt;em&gt;memory creation phase&lt;/em&gt;&lt;/strong&gt;. Let's go to the next phase. The &lt;strong&gt;&lt;em&gt;code execution phase&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 2 - Code execution phase
&lt;/h3&gt;

&lt;p&gt;In this phase, javascript goes through the code line by line again but this time it replaces the &lt;strong&gt;undefined&lt;/strong&gt; with the actual values given to the variables.&lt;/p&gt;

&lt;p&gt;Let's see what happens when we encounter the first line in the code execution phase.&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%2F4vhr5vbt7k6ymsw3wm5i.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%2F4vhr5vbt7k6ymsw3wm5i.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure 11&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When javascript goes through the 1st line again, it stores the value(&lt;strong&gt;3&lt;/strong&gt;) assigned to the variable &lt;code&gt;num&lt;/code&gt; inside the memory component. The memory component now looks like this. (&lt;em&gt;figure12&lt;/em&gt;)&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%2F95khr8ku9gpmb7imqnwp.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%2F95khr8ku9gpmb7imqnwp.png" alt="GCE code exec 1"&gt;&lt;/a&gt;&lt;em&gt;figure 12&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Next, it moves to the 2nd line where the function is declared and this time, the code is completely skipped till the function ends as it is already stored in the memory component during the memory creation phase.&lt;/p&gt;

&lt;p&gt;Now we move to the 6th line and this is where things gets interesting. In this line we invoke a function &lt;code&gt;double&lt;/code&gt; with the parenthesis &lt;code&gt;()&lt;/code&gt;. This creates an execution context for that function inside the global execution context just like in &lt;em&gt;figure13&lt;/em&gt;.&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%2Fzwswm5ag7875d1x0n57r.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%2Fzwswm5ag7875d1x0n57r.png" alt="13"&gt;&lt;/a&gt;&lt;em&gt;figure13&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Just like the whole code has a global execution context, every function has its own execution context in which all the variables inside the function are stored. It is like Inception, a dream inside a dream and here we have an execution context inside an execution context. The same process is followed here. First the memory creation phase and then the code execution phase. A memory location is reserved for the variable &lt;code&gt;number&lt;/code&gt; which is the parameter passed to the function. The value given is &lt;strong&gt;undefined&lt;/strong&gt;. Same goes for the variable &lt;code&gt;ans&lt;/code&gt;. This is how the execution context looks like after the memory creation phase.&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%2Fwd5dy3wlwqewddvg7bqo.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%2Fwd5dy3wlwqewddvg7bqo.png" alt="14"&gt;&lt;/a&gt;&lt;em&gt;figure14&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Moving on to the code execution phase line by line.&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%2Fb0lex935do7c381eoclk.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%2Fb0lex935do7c381eoclk.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure15&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In line 2 the value assigned to the variable &lt;code&gt;number&lt;/code&gt; is &lt;strong&gt;3&lt;/strong&gt; because when we invoked the function, we passed &lt;code&gt;num&lt;/code&gt; as an argument to the function which is &lt;strong&gt;3&lt;/strong&gt;. The &lt;strong&gt;undefined&lt;/strong&gt; value of &lt;code&gt;number&lt;/code&gt; is replaced with &lt;strong&gt;3&lt;/strong&gt;.&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%2Fvw2fmobqq9hz6wbfm0uk.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%2Fvw2fmobqq9hz6wbfm0uk.png" alt="16"&gt;&lt;/a&gt;&lt;em&gt;figure16&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Moving on to line 3.&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%2Fq9hduxhz4iape8p69b81.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%2Fq9hduxhz4iape8p69b81.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure17&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The value stored in &lt;code&gt;ans&lt;/code&gt; is &lt;code&gt;number * 2&lt;/code&gt; which is &lt;code&gt;3 * 2&lt;/code&gt; which is equal to &lt;strong&gt;6&lt;/strong&gt;. So the &lt;strong&gt;undefined&lt;/strong&gt; value of &lt;code&gt;ans&lt;/code&gt; is replaced with &lt;strong&gt;6&lt;/strong&gt;.&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%2F0qpgj0ro9txle8qhbxb6.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%2F0qpgj0ro9txle8qhbxb6.png" alt="17"&gt;&lt;/a&gt;&lt;em&gt;figure18&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let us move to line 4.&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%2Frgqo5vxedw3yhwl7rkzc.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%2Frgqo5vxedw3yhwl7rkzc.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure19&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When javascript encounters the &lt;code&gt;return&lt;/code&gt; keyword, it takes the value of &lt;code&gt;ans&lt;/code&gt; being returned which is &lt;strong&gt;6&lt;/strong&gt; and stores it inside the &lt;code&gt;doubleNum&lt;/code&gt; variable inside the global execution context.&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%2Fmvwcxfgcgd7sr1acb5rh.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%2Fmvwcxfgcgd7sr1acb5rh.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure20&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After the function is completed executing, the execution context for that function is deleted and the control returns to the global execution context.&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%2Flx4ypzxoq4flizwr963v.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%2Flx4ypzxoq4flizwr963v.png" alt="image"&gt;&lt;/a&gt;&lt;em&gt;figure21&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since we have executed the last line, the global execution context gets deleted which marks the end of the program.&lt;/p&gt;

&lt;h3&gt;
  
  
  End of program
&lt;/h3&gt;

&lt;p&gt;This was the journey of code execution in javascript. Thank you for reading my first blog. More to come as I learn new things.&lt;/p&gt;

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