<?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: Raj Kishor Shaw</title>
    <description>The latest articles on Forem by Raj Kishor Shaw (@rkshaw20).</description>
    <link>https://forem.com/rkshaw20</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%2F901266%2F0d2f9792-5a4e-421e-9964-0e3da4c23cbc.jpg</url>
      <title>Forem: Raj Kishor Shaw</title>
      <link>https://forem.com/rkshaw20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rkshaw20"/>
    <language>en</language>
    <item>
      <title>== vs === in JavaScript</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Tue, 14 Feb 2023 08:22:00 +0000</pubDate>
      <link>https://forem.com/rkshaw20/-vs-in-javascript-2457</link>
      <guid>https://forem.com/rkshaw20/-vs-in-javascript-2457</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In javascript, the equality operator is used to determine whether two values are equal. The main difference between the "==" and "===" operators in javascript is that the "==" operator does the type conversion of the operands before the comparison, whereas the "===" operator compares the values and their data types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;p&gt;In this blog, we will learn about the "==" and "===" operators in JavaScript and will try to understand both of them with examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In our day-to-day life, we all face multiple situations where we need to compare two things. For example, we all use Twitter and Discord. When we visit the app, we see a login page asking for a username and password, where we need to add our details. Once we submit the details, the website goes through its database and compares our provided details with the details available. It permits you to log in if the details match; otherwise, it doesn't. This is one of many cases where two items are compared, and the outcome is used to determine the next course of action.&lt;/p&gt;

&lt;p&gt;In JavaScript when we need to compare two values and decide whether values are equal or not we use the following operator&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Loose equality("==")&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Strict equality("===")&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; - Equality operators return a boolean value.&lt;/p&gt;

&lt;p&gt;Which operations we choose depends on what sort of comparison we are looking to perform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Double Equal (==) vs Triple Equal (===)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is "==" operator ?
&lt;/h3&gt;

&lt;p&gt;The "==" is also known as the &lt;strong&gt;loose equality&lt;/strong&gt; operator. The main purpose is to check whether its two operands are equal after &lt;strong&gt;type conversion&lt;/strong&gt;. It returns true if both the operands are of the same value or if both of them are of different types then either of them will be converted to the data type of the other operand and have the same value. It will return false if both operands have different values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The "==" operator does a type conversion of elements before comparing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, let's first understand, what is type conversion ?
&lt;/h2&gt;

&lt;p&gt;When comparing two operands, the "==" operator tends to transform either of them into the other operand's type if they are not of the same data type before performing a loose comparison of their values.&lt;/p&gt;

&lt;p&gt;Type conversion is the main difference between the "==" and "===" operators in JavaScript.&lt;/p&gt;

&lt;p&gt;Let's understand it with an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const x=21;
const y='21';
console.log(x==y); //true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, x is a number and y is a string. The "==" operator first converts the y value to a number type and then it is compared to x. Since both the values are the same it returns true.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the "===" operator?
&lt;/h2&gt;

&lt;p&gt;The "===" is also known as the &lt;strong&gt;strict equality&lt;/strong&gt; operator. It compares both the values of the operands without performing type conversion. If the values have different data types, the values are considered unequal. If the values are of the same data type and have the same value then they are considered equal.&lt;/p&gt;

&lt;p&gt;Let's understand it with an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const x = 2;
const y = 2;
const z = '2';
console.log(x===y); //true
console.log(x===z); //false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, x and y are numbers but z is a string value. So, after a comparison of x and y, it is returning true but as z is a string it is returning false.&lt;/p&gt;

&lt;h2&gt;
  
  
  Few Examples of both operators:
&lt;/h2&gt;

&lt;p&gt;Example 1: Comparing a number with a string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const x= 5;
const y ='5';
console.log(x==y); // true
console.log(x===y); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 2: Comparing objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name1 = { name: "Raj" }
const name2 = { name: "Raj" }
console.log(name1==name1); // true
console.log(name1=name2); // false
console.log(name1===name1); // true
console.log(name1===name2); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the first output returns true because name1 and name1 refer to the same instance whereas the name1 and name2 return false because it refers to different instances. Never compare the objects with the "==" operator as different objects with the same value are not equal.&lt;/p&gt;

&lt;p&gt;Example 3: comparing boolean and number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(true == 1) // true
console.log(true === 1) // false
console.log(false == 0) // true
console.log(false === 0) // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the first operand is of boolean type and the second one is of number type. The "==" operator does the type conversion of a number into a boolean (as 1 is considered true and 0 is considered false in boolean).&lt;/p&gt;

&lt;p&gt;Example 4: Comparing null and undefined&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const x = null;
const y ;
console.log(x==y); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, it returns true because the comparison of null and undefined is true.&lt;/p&gt;

&lt;p&gt;Example 5: When operand values are NaN(not a number).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const x= NaN;
const y= NaN;
console.log(x==y); // false
console.log(x===y); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, after comparing both two NaN values it returns false because the equality operator treats NaN as unequal to every other value including itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To gain confidence in this topic practice all the above examples.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The "==" and "===" operators are used to check the equality of two operands.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The "==" is the loose operator and the "===" is the Strict operator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The "==" does the type conversion before checking and the "===" does not do the type conversion before checking.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's generally considered a best practice to use the strict equality operator "===" when making comparisons in JavaScript, as it avoids unexpected behavior that could be introduced by type conversion.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>easy</category>
    </item>
    <item>
      <title>'==' vs '===' in JavaScript</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Tue, 14 Feb 2023 07:36:30 +0000</pubDate>
      <link>https://forem.com/rkshaw20/-vs-in-javascript-1748</link>
      <guid>https://forem.com/rkshaw20/-vs-in-javascript-1748</guid>
      <description>&lt;p&gt;As a developer many times, we see other developers using &lt;strong&gt;Strict Equality Operator(===)&lt;/strong&gt; instead of &lt;strong&gt;Abstract Equality Operator(==)&lt;/strong&gt; and wonder if there is really any major difference between the two? Let's deep dive in to see what's beneath them.&lt;/p&gt;

&lt;p&gt;Strict Equality Operator(===) behaves similarly to Abstract Equality Operator(==) except no type conversion is done and the types must be the same to be considered equal.&lt;/p&gt;

&lt;p&gt;Abstract Equality Operator(==) will compare for equality after doing any necessary type conversions. &lt;/p&gt;

&lt;p&gt;The "===" operator will &lt;strong&gt;NOT&lt;/strong&gt; do any type conversions, so if the two values are not of the Same Type "===" will simply return false.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&lt;br&gt;
&lt;span class="hljs-string"&gt;'23'&lt;/span&gt; &lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; &lt;span class="hljs-number"&gt;23&lt;/span&gt;       &lt;span class="hljs-comment"&gt;// true&lt;/span&gt;&lt;br&gt;
&lt;span class="hljs-string"&gt;'23'&lt;/span&gt; &lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; &lt;span class="hljs-number"&gt;23&lt;/span&gt;      &lt;span class="hljs-comment"&gt;// false&lt;/span&gt;

&lt;p&gt;&lt;span&gt;" "&lt;/span&gt; &lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt; &lt;span&gt;0&lt;/span&gt;            &lt;span&gt;// true&lt;/span&gt;&lt;br&gt;
&lt;span&gt;" "&lt;/span&gt; &lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt; &lt;span&gt;0&lt;/span&gt;            &lt;span&gt;// false&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;0&lt;/span&gt; &lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;        &lt;span&gt;// true&lt;/span&gt;&lt;br&gt;
&lt;span&gt;0&lt;/span&gt; &lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt; &lt;span&gt;false&lt;/span&gt;       &lt;span&gt;// false&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;null &lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt; undefined  &lt;span&gt;// true&lt;/span&gt;&lt;br&gt;
null &lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;=&lt;/span&gt; undefined  &lt;span&gt;// false&lt;/span&gt;&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;

&lt;p&gt;Remember devs, if you want to compare equality between two values without any unnecessary type conversion, use Strict Equality Operator(===).&lt;/p&gt;




&lt;/blockquote&gt;

&lt;p&gt;I hope now you know the difference between the two operators.&lt;/p&gt;

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

&lt;p&gt;Sources: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;MDN Web Docs&lt;/li&gt;
&lt;li&gt;StackOverflow&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;This article is published w/ &lt;a href="https://scattr.io?ref=dev" rel="noopener noreferrer"&gt;Scattr  ↗️&lt;/a&gt;&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>gamedev</category>
      <category>strategygames</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Higher Order Functions</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Tue, 25 Oct 2022 10:00:10 +0000</pubDate>
      <link>https://forem.com/rkshaw20/higher-order-functions-397f</link>
      <guid>https://forem.com/rkshaw20/higher-order-functions-397f</guid>
      <description>&lt;p&gt;So, what are higher-order functions?&lt;/p&gt;

&lt;p&gt;Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.&lt;/p&gt;

&lt;p&gt;Example-Map, Filter, and Reduce&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Map&lt;/strong&gt;- It creates a new array by calling a function for every array element. It calls a function once for each element in an array. It does not execute the function for empty elements and does not change the original array.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V8WnooMC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ei5s0faz38nlstdgb9yn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V8WnooMC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ei5s0faz38nlstdgb9yn.jpg" alt="Image description" width="396" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pBuBRV0H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5f4b406p7d9fsi4o3dgt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pBuBRV0H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5f4b406p7d9fsi4o3dgt.jpg" alt="Image description" width="541" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above example shows how easily we can get the desired result using the map function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filter&lt;/strong&gt;-It creates a new array filled with elements that pass a test provided by a function.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HZEd_TWT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rtmdxfraz3g3mez3plgg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HZEd_TWT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rtmdxfraz3g3mez3plgg.jpg" alt="Image description" width="423" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--muC1EeQm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jubtls84hyvxwnmw01c.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--muC1EeQm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jubtls84hyvxwnmw01c.jpg" alt="Image description" width="387" height="60"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reduce&lt;/strong&gt;- It executes a reducer function for the array element. It returns a single value and the function's accumulated result.&lt;/p&gt;

&lt;p&gt;Example-  for explaining this I will first show you how to get the result without reduce the function and then I will show you how you can get the same result with reduce function. Then will compare the two approaches.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a-Yy3b8d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eljiuz6b4jx1ftj6j5eo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a-Yy3b8d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eljiuz6b4jx1ftj6j5eo.jpg" alt="Image description" width="453" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;output-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9KzSAJHQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me8c60xujzhrlvnae376.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9KzSAJHQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me8c60xujzhrlvnae376.jpg" alt="Image description" width="512" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In line number 5, I used a normal approach and in line number 17 I used reduce function to get the same result.&lt;/p&gt;

&lt;p&gt;In line number 17 you can see that I have used 'acc' it is used to accumulate the value and it serves the same purpose as 'sum' in line number 8. &lt;br&gt;
Then 'curr' is in line 17. It is the current value that we are getting while iterating over the array. It has the same purpose as what 'arr[i]' is providing us in line number 8.&lt;/p&gt;

&lt;p&gt;We can also user &lt;strong&gt;Map and filter&lt;/strong&gt; functions at the same time.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aJJaa3u3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2r4cfaoyrnyk6s1t9h6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aJJaa3u3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2r4cfaoyrnyk6s1t9h6.jpg" alt="Image description" width="632" height="241"&gt;&lt;/a&gt;&lt;br&gt;
Output-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hZC-X4vc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9s2m63nsqtdmuzw0jkzh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hZC-X4vc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9s2m63nsqtdmuzw0jkzh.jpg" alt="Image description" width="493" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also get the same result using  *&lt;em&gt;Reduce *&lt;/em&gt; function also.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9uj3Xjuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/np0v4r9tr18zt2lkhy3i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9uj3Xjuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/np0v4r9tr18zt2lkhy3i.jpg" alt="Image description" width="513" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XUGbipJT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pma8zswt4p87b8lt6r0s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XUGbipJT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pma8zswt4p87b8lt6r0s.jpg" alt="Image description" width="493" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was all about Map, filter, and reduce functions. I have learned all this from the &lt;a href="https://www.youtube.com/playlist?list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP"&gt;Namaste JavaScript&lt;/a&gt; series by &lt;a href="https://twitter.com/akshaymarch7"&gt;Akshay Saini&lt;/a&gt;. If you want to fall in love with JavaScript then you should learn from this.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>map</category>
    </item>
    <item>
      <title>JavaScript Engine</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Fri, 21 Oct 2022 09:00:35 +0000</pubDate>
      <link>https://forem.com/rkshaw20/javascript-engine-j3o</link>
      <guid>https://forem.com/rkshaw20/javascript-engine-j3o</guid>
      <description>&lt;p&gt;No, It is not hardware it is just a software code that is present in every browser. &lt;br&gt;
In this blog, I will talk about the JavaScript (js) engine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript Runtime Environment(JSE)&lt;/strong&gt;- Every browser has JSE in it. JSE consists of a Js engine that executes the JS code and it is also the heart of JSE. JSE contains a Js engine, API, callback queue, microtask queue, and an event loop.&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%2F7t0q1kjcdgyqynieej9k.jpg" 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%2F7t0q1kjcdgyqynieej9k.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the Js engine, there are different steps for getting the output. The Js code that we write at first go for parsing. In the parsing step, our code is broken down into tokens like in the below image we can see that let, a, =, and 7 are broken down into tokens.&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%2F0jyr49lg7ugqov9bjtlp.jpg" 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%2F0jyr49lg7ugqov9bjtlp.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code is then passed to a syntax parser the job of this is to take our code and broke it into Abstract Syntax Tree(AST).&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%2Ffcjh778xj305amvsct8f.jpg" 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%2Ffcjh778xj305amvsct8f.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's understand the &lt;strong&gt;interpreter&lt;/strong&gt; and &lt;strong&gt;compiler&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpreter&lt;/strong&gt;-  The job of the interpreter is to take the code and execute it line by line. It is fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compiler&lt;/strong&gt;- In this our whole code is compiled first even before execution and a new code is formed which is the optimized version of our code and then it is executed. The optimized code runs very fast. It is efficient.&lt;/p&gt;

&lt;p&gt;Now, coming to the main part. When JavaScript was first invented by Brendan Eich, it uses an interpreter to execute the code. But modern browser like the V8 engine uses &lt;strong&gt;Just In Time(JIT) compilation&lt;/strong&gt;. Which uses both interpreter and a compiler for code execution. Compilation and execution go hand in hand. Our AST goes to an interpreter and it goes for execution and at the same time compiles the code which is executed line by line by the interpreter.&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%2Fjlvakbjqwa7pxiailqbt.jpg" 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%2Fjlvakbjqwa7pxiailqbt.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In some engines, there is also AOT(ahead of time) compilation. It takes the code and compiles it before execution.&lt;/p&gt;

&lt;p&gt;A memory heap is used for storing variables. A garbage collector(GC) is used for collecting garbage value. O is for optimization. &lt;br&gt;
Garbage collection uses a &lt;a href="https://www.geeksforgeeks.org/mark-and-sweep-garbage-collection-algorithm/" rel="noopener noreferrer"&gt;mark and sweep algorithm&lt;/a&gt; for freeing memory.&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%2Fr1dz290rwf3dlc1p17s0.jpg" 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%2Fr1dz290rwf3dlc1p17s0.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At present &lt;strong&gt;V8 engine&lt;/strong&gt; of google is the best engine for JavaScript. &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%2Fngmxzlr9buy84q4frmy6.jpg" 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%2Fngmxzlr9buy84q4frmy6.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have read all this from the &lt;a href="https://www.youtube.com/playlist?list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP" rel="noopener noreferrer"&gt;Namaste JavaScript&lt;/a&gt; series by &lt;a href="https://twitter.com/akshaymarch7" rel="noopener noreferrer"&gt;Akshay Saini&lt;/a&gt;. If you want to fall in love with JavaScript then you should learn from this.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Closures in JavaScript</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Fri, 21 Oct 2022 07:36:49 +0000</pubDate>
      <link>https://forem.com/rkshaw20/closures-in-javascript-43jj</link>
      <guid>https://forem.com/rkshaw20/closures-in-javascript-43jj</guid>
      <description>&lt;p&gt;In this blog, I have told everything about closures.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What are closures?&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Closures are a combination of a function and its lexical scope bundled together to form a closure.&lt;/p&gt;

&lt;p&gt;A function along with reference to its outer environment together forms a closure.&lt;/p&gt;

&lt;p&gt;Every function in JavaScript has its axis to its outer lexical environment i.e. access to every variable present in its parent environment. So even if this function is executed in some other scope it still remembers its outer lexical environment where it was originally present in its code. This is what closure is.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7unZkYUC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hycjhdijqc5lbh7ejt1o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7unZkYUC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hycjhdijqc5lbh7ejt1o.jpg" alt="Image description" width="317" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GOwWPgC7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/81jv1adb9y9l6f5om48y.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GOwWPgC7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/81jv1adb9y9l6f5om48y.jpg" alt="Image description" width="880" height="74"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Line 3 to 5 along with its outer lexical environment forms a closure. The two parentheses used in line number 9 are used to call the inner function. The closure also doesn't follow any sequence. If we move line number 2 to after line number 5  then also inner function with its outer environment will form closure.&lt;/p&gt;

&lt;p&gt;If we use the *&lt;em&gt;Let *&lt;/em&gt; variable also then also it will give the same output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H8c0IMwh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yl54ka5jgn1acmzgylld.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H8c0IMwh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yl54ka5jgn1acmzgylld.jpg" alt="Image description" width="303" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9e2rWVSq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m580by5z8r3frmjifiv7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9e2rWVSq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m580by5z8r3frmjifiv7.jpg" alt="Image description" width="880" height="74"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we give a parameter in line number 1 then also the inner function will print the parameter value because the inner function had formed a closure with its outer environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PriG-mIN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3b6x6j9su2w2ua2t0jg4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PriG-mIN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3b6x6j9su2w2ua2t0jg4.jpg" alt="Image description" width="330" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--okUGjn4t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s864d7o9g1y3mm5u1wcu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--okUGjn4t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s864d7o9g1y3mm5u1wcu.jpg" alt="Image description" width="308" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even if the outer function is nested inside another function, then also inner function will have access to the variable of the outest function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w1BvxMBt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/japm2vbiva2z2z0kbmtg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w1BvxMBt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/japm2vbiva2z2z0kbmtg.jpg" alt="Image description" width="438" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1RNvz0fl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb830w1qjybgsifvv3s5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1RNvz0fl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb830w1qjybgsifvv3s5.jpg" alt="Image description" width="307" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we give a conflicting let variable on line number 12 then also it will print 10 because it has accessed the line number 7 variable. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZhZR-964--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kkl5t12zauffbipepbja.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZhZR-964--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kkl5t12zauffbipepbja.jpg" alt="Image description" width="410" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PxUvJzYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfrrsznp3ieqrh7tbv4e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PxUvJzYG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfrrsznp3ieqrh7tbv4e.jpg" alt="Image description" width="307" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if we remove line number 7 then it will go deeper in the hierarchy and at last, it will to the global scope to resolve this let variable and it will print its value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P3SiHihh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rm8s7mnut28z3p99m6bm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P3SiHihh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rm8s7mnut28z3p99m6bm.jpg" alt="Image description" width="442" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zCCJRo62--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/599jpvwmveg30dx049pl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zCCJRo62--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/599jpvwmveg30dx049pl.jpg" alt="Image description" width="292" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Closures
&lt;/h2&gt;

&lt;p&gt;Closures are the most beautiful and important part of JavaScript. It has many advantages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It is used in module patterns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is used in function courring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is used in higher-order functions like memoize and ones.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The most important use is in &lt;strong&gt;Data hiding&lt;/strong&gt; and &lt;strong&gt;encapsulation&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Data Hiding-&lt;/strong&gt; Suppose we have one variable and we want to protect it. We don't want other functions and code to have access to this data. In other words, we can say that we want to encapsulate this data from other pieces of code.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4F0mfGDm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46rogrvxa44wh1ljhhmg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4F0mfGDm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/46rogrvxa44wh1ljhhmg.jpg" alt="Image description" width="316" height="173"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bkAzYbEh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngczioa3hfmfwzbgd7vn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bkAzYbEh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngczioa3hfmfwzbgd7vn.jpg" alt="Image description" width="409" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we can see that we have made a function and protected our count variable. No one from outside can have access to it.&lt;/p&gt;

&lt;p&gt;To get access we have to add a return function in line number 3 and it will form a closure.&lt;br&gt;
We can create a variable counter1 and call it to access to count variable.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1v8-Y2Zh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zkfymnu2158bc6gfhm5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1v8-Y2Zh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zkfymnu2158bc6gfhm5.jpg" alt="Image description" width="302" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rcCVzuRp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yhxbq75bhn2hlgqhtmf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rcCVzuRp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yhxbq75bhn2hlgqhtmf.jpg" alt="Image description" width="408" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we create a new variable counter2 and call the counter function then it will create a new closure and the count variable will again start from 0.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0brMpSNy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40ogqphoqx95ngm1yjvk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0brMpSNy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40ogqphoqx95ngm1yjvk.jpg" alt="Image description" width="346" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a8gE9U5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en6dxyykb491a4jpszjt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a8gE9U5E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en6dxyykb491a4jpszjt.jpg" alt="Image description" width="404" height="69"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above image, we can see that the first two output is from counter1 and the third one is from counter2.&lt;/p&gt;

&lt;p&gt;If want to make this code good and scalable then we can do this which I have shown in the example below. I have created a constructor here. It will still form closure and our data is protected.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_KajRBa3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfvljnqvlk7si0qyq5ye.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_KajRBa3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfvljnqvlk7si0qyq5ye.jpg" alt="Image description" width="524" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6WGj-1df--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9grb3pfpyg942iy76yr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6WGj-1df--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9grb3pfpyg942iy76yr.jpg" alt="Image description" width="404" height="69"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantage of closures&lt;/strong&gt;- The major disadvantage of closures is that sometimes there can be over consumptions of memory in a closure because every time a closure is formed it consumes a lot of memory and sometimes those closed-over variables are not garbage collected before the program expires. If this is not handled properly then it may lead to a memory leak and may freeze the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Garbage Collector&lt;/strong&gt;- It is in the JavaScript engine to freeze or take the variables which are not used. &lt;/p&gt;

&lt;p&gt;Garbage collectors and closures are related to each other.&lt;br&gt;
In the below example, we can see that in line number 3, variable x and z both of them form a closure but when z is not used then in modern JavaScript engines line V8 it is garbage collected and freed from the memory. That is why it gives not defined when we try to access it.&lt;/p&gt;

&lt;p&gt;Example-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5J1yb4tP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w81zwbje0tbbtfzqg4jz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5J1yb4tP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w81zwbje0tbbtfzqg4jz.jpg" alt="Image description" width="434" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mGgO4oGo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lrppqpghnzan1jhhjtf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mGgO4oGo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lrppqpghnzan1jhhjtf.jpg" alt="Image description" width="656" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is all about closures. I have read all this from the &lt;a href="https://www.youtube.com/playlist?list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP"&gt;Namaste JavaScript&lt;/a&gt; series by &lt;a href="https://twitter.com/akshaymarch7"&gt;Akshay Saini&lt;/a&gt;. If you want to fall in love with JavaScript then you should learn from this.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Var, Let, and Const</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Fri, 02 Sep 2022 12:33:27 +0000</pubDate>
      <link>https://forem.com/rkshaw20/var-let-and-const-odn</link>
      <guid>https://forem.com/rkshaw20/var-let-and-const-odn</guid>
      <description>&lt;p&gt;We all have used var, let, and const variables many times in JavaScript but sometimes we all get confused about which is the best variable to use for a particular program. I am writing this blog to understand let, var, and const variables for helping someone to clear their basics regarding the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Var
&lt;/h2&gt;

&lt;p&gt;It is the oldest keyword to declare a variable in JavaScript. The scope of it is global or function scope. Variables defined outside the function can be accessed globally and variables defined inside a particular function can be accessed within the function.&lt;br&gt;
It can be updated and re-declared into the scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt; -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function f() {
        var a = 7;
        console.log(a)
    }
    f();
    console.log(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7
ReferenceError: a is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let
&lt;/h2&gt;

&lt;p&gt;It is an improved version of the var keyword. The scope of a let keyword is only block scoped. It cannot be accessible outside the particular block.&lt;br&gt;
It can be updated but cannot be re-declared into the scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    let a =7;
    function f() {
        if (true) {
            let b = 9

            // It prints 9
            console.log(b);
        }

        // It gives error as it
        // defined in if block
        console.log(b);
    }
    f()

    // It prints 7
    console.log(a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9
ReferenceError: b is not defined
7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 7
if (true) {
    let a=9
    console.log(a) // It prints 9
}
console.log(a) // It prints 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9
7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Const
&lt;/h2&gt;

&lt;p&gt;It has all the properties same as the let keyword, except the user cannot update it. It cannot be updated or re-declared into the scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const a = {
        prop1: 7,
        prop2: 9
    }

    // It is allowed
    a.prop1 = 3

    // It is not allowed
    a = {
        b: 7,
        prop2: 9
    }

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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Most Used Git Commands</title>
      <dc:creator>Raj Kishor Shaw</dc:creator>
      <pubDate>Mon, 01 Aug 2022 09:01:00 +0000</pubDate>
      <link>https://forem.com/rkshaw20/most-used-git-commands-4899</link>
      <guid>https://forem.com/rkshaw20/most-used-git-commands-4899</guid>
      <description>&lt;p&gt;I heard the term Git and GitHub a few months back when a discord community had organized an event for beginners in open-source. You just had to submit a meaningful pull request after taking a Good-first issue and solving the issue. I won a Swag T-shirt for changing some designs on the landing page of the &lt;a href="https://app.amplication.com/"&gt;Amplication&lt;/a&gt; website.&lt;/p&gt;

&lt;p&gt;I wanted to learn about git commands for contributing to the above-mentioned event. I learned about some of the commands that programmer uses in their daily life for contributing to open source projects. I am adding some of the most used git commands that will help beginners in getting started in the open-source world.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;$ git init&lt;/strong&gt;&lt;br&gt;
It is used to create a new Git repository. It creates all the necessary files and directories for git to keep track of everything.&lt;br&gt;
It creates a file with the name .git and keep all the necessary file in it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git config&lt;/strong&gt;&lt;br&gt;
If you are first time using git, you need to configure it. This command allows you to specify the username and email address that will be used with your commits.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;#### for setting up Git with your name &lt;br&gt;
 &lt;code&gt;git config --global user.name "&amp;lt;Your-Full-Name&amp;gt;"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;#### for setting up Git with your email&lt;br&gt;
 &lt;code&gt;git config --global user.email "&amp;lt;your-email-address&amp;gt;"&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git clone&lt;/strong&gt;&lt;br&gt;
This command helps you to clone a remote repository to your GitHub and your local system. It downloads all the code related to that repository to your machine. You need to download all the codes of a working remote repository to your system for working with it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git status&lt;/strong&gt;&lt;br&gt;
This command helps you to check the status of your repository. It will tell you every information related to it. If you are a beginner using this command will help you a lot.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git diff&lt;/strong&gt;&lt;br&gt;
This command helps you to check the difference between the working tree to the changes that you have made in your local file before saving the file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git add&lt;/strong&gt;&lt;br&gt;
This command helps you to move your file from the working directory to the staging index. This is a necessary step before committing your file to the remote repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git commit&lt;/strong&gt;&lt;br&gt;
This command saves a log message along with the commit id of the modification you made to the git repository. You have to add a commit message in it describing the changes you made. This message will show up in your repository after opening a pull request.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;$ git commit –m "&amp;lt;Type your commit message here&amp;gt;"&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git push&lt;/strong&gt;&lt;br&gt;
This command helps you to push the files of your local repository to the remote repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git branch&lt;/strong&gt;&lt;br&gt;
This command helps you to add a new branch, list all the existing branches, and delete the branch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git merge&lt;/strong&gt;&lt;br&gt;
This command helps you to join your branch to the parent branch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git pull&lt;/strong&gt;&lt;br&gt;
This command is used to fetch and integrate the remote repository to your local repository. It helps you to be updated with the latest changes that have been made in the repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;git log&lt;/strong&gt;&lt;br&gt;
This command is used to show all &lt;br&gt;
repository commits that had been made in the past.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;cd — Returns you to your login directory.&lt;/li&gt;
&lt;li&gt;cd - — Returns you to your previous working directory.&lt;/li&gt;
&lt;li&gt;cd ~ — Also returns you to your login directory.&lt;/li&gt;
&lt;li&gt;cd / — Takes you to the entire system's root directory.&lt;/li&gt;
&lt;li&gt;cd /root — Takes you to the home directory of the root user.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>github</category>
      <category>webdev</category>
      <category>git</category>
    </item>
  </channel>
</rss>
