<?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: AnshulJS</title>
    <description>The latest articles on DEV Community by AnshulJS (@anshulnautiyal).</description>
    <link>https://dev.to/anshulnautiyal</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%2F332436%2F21753bcb-b7db-46ea-ba87-d76bb7a566f0.jpg</url>
      <title>DEV Community: AnshulJS</title>
      <link>https://dev.to/anshulnautiyal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anshulnautiyal"/>
    <language>en</language>
    <item>
      <title>Hoisting in JS. (Part 1 - variable Hoisting)</title>
      <dc:creator>AnshulJS</dc:creator>
      <pubDate>Tue, 02 Feb 2021 12:23:19 +0000</pubDate>
      <link>https://dev.to/anshulnautiyal/hoisting-in-js-part-1-variable-hoisting-jg0</link>
      <guid>https://dev.to/anshulnautiyal/hoisting-in-js-part-1-variable-hoisting-jg0</guid>
      <description>&lt;p&gt;&lt;b&gt;Prerequisite:&lt;/b&gt; Basic knowledge of JS&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;What is Hoisting?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;In simple words, it means you can use a variable before declaring it (variable declaration is a must).&lt;/p&gt;

&lt;p&gt;Ok, what that means? Can’t I use a variable without declaring it?&lt;/p&gt;

&lt;p&gt;No, you can’t. You have to declare a variable to use it.&lt;/p&gt;

&lt;p&gt;For example:&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%2Fi%2F991j5kqf99i29k17aunz.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%2Fi%2F991j5kqf99i29k17aunz.png" alt="Screenshot 2021-02-01 at 11.48.05 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am using variable &lt;strong&gt;x&lt;/strong&gt; without declaring it and I got an error. This behavior is common in almost all programming languages. (I guessed)&lt;/p&gt;

&lt;p&gt;Ok, now you know that you have to declare a variable to use it.&lt;/p&gt;

&lt;p&gt;But now you have the below questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What do you mean by variable declaration?&lt;/li&gt;
&lt;li&gt;How JS engine know that this is a variable declaration?&lt;/li&gt;
&lt;li&gt;Where should I declare a variable? I mean physical location in your code. That is either before or after using a variable?&lt;/li&gt;
&lt;li&gt;Where is hoisting in all of this?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let answered them one by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What do you mean by variable declaration?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In JS, If you want to store data in your code you use variables to store them. For that, you inform the JS engine by saying that “Hey JS engine, I want to store some data in my code so I am going to declare a variable to just inform you.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;var x;&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;This is called a variable declaration. &lt;code&gt;var x&lt;/code&gt; this exact piece of code tells the JS engine that you declare a variable and named it &lt;strong&gt;x&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JS provides 3 keywords to declare a variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var&lt;br&gt;
const &lt;br&gt;
let&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this article, I will use the &lt;strong&gt;var&lt;/strong&gt; keyword.&lt;/p&gt;

&lt;p&gt;Just Remember when you declare a variable with &lt;strong&gt;var&lt;/strong&gt; keyword, behind the scene JS engine allocates memory for it. That's why you have to declare a variable to use it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;JS engine&lt;/strong&gt; is responsible for executing your JS code. Your JS code is feed into the JS engine and then it spits out the final output. That’s why browsers understand JS code because every major browser comes with its own JS engine like chrome have V8 engine, the edge has Chakra, Mozilla have SpiderMonkey.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Check more: &lt;a href="https://en.wikipedia.org/wiki/List_of_ECMAScript_engines" rel="noopener noreferrer"&gt;List of JS engine&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;How does the JS engine know that this &lt;code&gt;var x&lt;/code&gt; is a variable declaration?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;These keywords &lt;em&gt;(var, const, let)&lt;/em&gt; help the JS engine to identify that a variable is declared.&lt;/p&gt;

&lt;p&gt;So when the JS engine sees the below code:&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%2Fi%2Fpdw7u7ulhe97923ts747.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%2Fi%2Fpdw7u7ulhe97923ts747.png" alt="Screenshot 2021-02-02 at 12.20.17 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JS engine is like “Oh I got it. You declared a variable.”&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Where should I declare a variable? I mean physical location in your code. That is either before or after using a variable?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To answer this question, let me show you 2 examples.&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%2Fi%2F099u98m4bysrlj1wc9be.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%2Fi%2F099u98m4bysrlj1wc9be.png" alt="Screenshot 2021-02-02 at 12.24.40 AM"&gt;&lt;/a&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%2Fi%2Fj2icta6wq7snjibiu393.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%2Fi%2Fj2icta6wq7snjibiu393.png" alt="Screenshot 2021-02-02 at 12.25.08 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 1st example, I first declare a variable and then use it by printing its output.&lt;br&gt;
In 2nd example, I first use it by printing its output and then declare the x variable.&lt;/p&gt;

&lt;p&gt;In most programming languages, you cannot use a variable before declaring it.&lt;/p&gt;

&lt;p&gt;But in JS, you can. And that's where hoisting comes into the picture.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Where is hoisting in all of this?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Both ways of declaring variable in JS are fine until you use &lt;code&gt;"use strict"&lt;/code&gt; in your code.&lt;em&gt;(called strict mode)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In strict mode, you cannot use a variable before declaring it.&lt;/p&gt;

&lt;p&gt;But to understand hoisting, we skip the strict mode.&lt;/p&gt;

&lt;p&gt;In beginning, I told you that hoisting helps you to use a variable before declaring it with the &lt;strong&gt;var&lt;/strong&gt; keyword. &lt;/p&gt;

&lt;p&gt;can you guess the output of the below code?&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(x);
var x;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

&lt;/div&gt;



&lt;p&gt;Both will print &lt;code&gt;undefined&lt;/code&gt;. This means &lt;strong&gt;x&lt;/strong&gt; gets &lt;code&gt;undefined&lt;/code&gt; as the default value.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How variable ** x ** get  &lt;code&gt;undefined&lt;/code&gt; as the default value?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let go step by step.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you do not assign a value to a variable then by default JS engine assigns &lt;code&gt;undefined&lt;/code&gt; as the default value. Yes, &lt;code&gt;undefined&lt;/code&gt; is a value in JS like number (1,2,3...) and character (a,b,c....)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ok, so both ways of writing look similar then where is the difference?&lt;/p&gt;

&lt;p&gt;The difference comes in how the JS engine parse it.&lt;br&gt;
To understand that you need to understand the different phases your code goes through.&lt;/p&gt;

&lt;p&gt;JS engine has 2 phase: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Memory creation phase&lt;/li&gt;
&lt;li&gt;Execution phase
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var x;
console.log(x);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's understand how the JS engine parse the above code.&lt;/p&gt;

&lt;p&gt;When the JS engine sees &lt;code&gt;var x&lt;/code&gt;, then it sees it as variable declaration, remember our 2nd question &lt;em&gt;How JS engine know that this is a variable declaration?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So after seeing it as variable declaration, JS engine takes the variable &lt;strong&gt;x&lt;/strong&gt; and store it in memory and assign &lt;code&gt;undefined&lt;/code&gt; as its value. This happens in the &lt;strong&gt;Memory creation phase&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Execution phase&lt;/strong&gt;, when it sees &lt;code&gt;console.log(x);&lt;/code&gt;, the JS engine says "I know what &lt;strong&gt;x&lt;/strong&gt; is. I already store it in memory during &lt;strong&gt;memory creation phase&lt;/strong&gt;." And since the JS engine already assigned &lt;code&gt;undefined&lt;/code&gt; as its value in this phase, so you will get &lt;code&gt;undefined&lt;/code&gt; output.&lt;/p&gt;
&lt;h4&gt;
  
  
  Explanation:-
&lt;/h4&gt;

&lt;p&gt;During the &lt;strong&gt;memory creation phase&lt;/strong&gt;, JS engine recognizes variable declarations as it reads the code, initializes them to &lt;code&gt;undefined&lt;/code&gt;, and puts them into memory to be used during the execution.&lt;/p&gt;

&lt;p&gt;So when JS engine start executing your code (&lt;strong&gt;Execution phase&lt;/strong&gt; started), all variable we use in the code, JS engine confirms their existence from &lt;strong&gt;Memory creation phase&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%2Fi%2F991j5kqf99i29k17aunz.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%2Fi%2F991j5kqf99i29k17aunz.png" alt="Screenshot 2021-02-01 at 11.48.05 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you know why we get a Reference error in the above code.&lt;br&gt;
When JS engine see &lt;code&gt;console.log(x);&lt;/code&gt;, It says "Ok... I do not see the &lt;strong&gt;x&lt;/strong&gt; variable stored in memory. (Why?) because there is no variable declaration code, so when it goes through the &lt;strong&gt;memory creation phase&lt;/strong&gt; it stores nothing in memory.&lt;br&gt;
And since the JS engine does not find the location/ reference of the &lt;strong&gt;x&lt;/strong&gt; variable in memory, so it throws a Reference error.&lt;/p&gt;

&lt;p&gt;Few...take a break because the next one is tricky.&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(x);
var x;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let start with how the JS engine will parse this code.&lt;/p&gt;

&lt;p&gt;Till now basic understanding will be like this, JS engine will see &lt;code&gt;console.log(x);&lt;/code&gt;, and then it will throw a Reference error same as what we see in the last example.&lt;/p&gt;

&lt;p&gt;But that's, not the case. Remember that our JS code will go through 2 phases. (memory and execution phase)&lt;br&gt;
So first JS engine will parse the complete code to identify all the variable declarations and then put them in memory with &lt;code&gt;undefined&lt;/code&gt; as their values. &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%2Fi%2Fb6crpl5dxgahutzx0wen.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%2Fi%2Fb6crpl5dxgahutzx0wen.png" alt="Screenshot 2021-02-02 at 2.24.59 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now behind the scene, your code looks like this.&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%2Fi%2Fe4ibimt916le2lkb145c.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%2Fi%2Fe4ibimt916le2lkb145c.png" alt="Screenshot 2021-02-02 at 2.32.56 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you get to know why few folk say that in hoisting your variable declaration move at the top of your code. Actually, it happened behind the scene, not on your actual code.&lt;/p&gt;

&lt;p&gt;Once the memory creation phase complete, your code moves to the execution phase. Now JS engine sees this &lt;code&gt;console.log(x);&lt;/code&gt; code and say "Yup I know it. This &lt;strong&gt;x&lt;/strong&gt; variable I already save in memory in last phase.". Then it will print &lt;code&gt;undefined&lt;/code&gt; as output.&lt;/p&gt;

&lt;p&gt;You see hoisting magic. You can access the &lt;strong&gt;x&lt;/strong&gt; variable before declaring it. In c# or java you can't access them before. You will get error there.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quiz
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(a);
var a = 10;
console.log(a);
a = 20;
console.log(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Hint: variable declaration is hoisted. Initialization do not.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;var a&lt;/code&gt; =&amp;gt; this is variable declaration.&lt;br&gt;
&lt;code&gt;= 10&lt;/code&gt; =&amp;gt; this is initialization.&lt;/p&gt;

&lt;p&gt;Comment your output and share how the above code looks behind the scene after going through the JS engine phases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Hoisting simply means you can access the variable before declaring it. It has its own pros and cons. But if you do not like hoisting then write code in strict mode (&lt;code&gt;use strict&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;I know &lt;code&gt;let&lt;/code&gt; &amp;amp; &lt;code&gt;const&lt;/code&gt; are not cover but let save them for a future post.&lt;br&gt;
Part 2 will cover how hoisting works with function. Is it the same or diff? &lt;/p&gt;

&lt;p&gt;Please share your thoughts here or on LinkedIn. If I missed something please comment below, I will update the post.&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>input type V/S button type: Part 1</title>
      <dc:creator>AnshulJS</dc:creator>
      <pubDate>Sun, 03 May 2020 17:36:23 +0000</pubDate>
      <link>https://dev.to/anshulnautiyal/input-type-v-s-button-type-part-1-4mn6</link>
      <guid>https://dev.to/anshulnautiyal/input-type-v-s-button-type-part-1-4mn6</guid>
      <description>&lt;p&gt;Let me ask you a question. Which one is better to use?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OyimrNdR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/36jf6qp3e0pp47zx2iky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OyimrNdR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/36jf6qp3e0pp47zx2iky.png" alt="input and button code" width="656" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It depends on 2 things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A scenario in which we are using it.&lt;/li&gt;
&lt;li&gt;Developer's choice.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Just think... why we do have 2 tags with the same attribute? Isn't input enough to do all sorts of things that a button can do?&lt;/p&gt;

&lt;p&gt;There must be a reason for it. Let's find out.&lt;/p&gt;

&lt;p&gt;I will divide this post into 3 parts.&lt;/p&gt;

&lt;p&gt;Part 1 - input type button V/S button type button&lt;br&gt;
Part 2 - input type reset V/S button type reset&lt;br&gt;
Part 3 - input type submit V/S button type submit&lt;/p&gt;

&lt;h3&gt;1. input type &lt;b&gt;button&lt;/b&gt; V/S button type &lt;b&gt;button&lt;/b&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OyimrNdR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/36jf6qp3e0pp47zx2iky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OyimrNdR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/36jf6qp3e0pp47zx2iky.png" alt="input and button code" width="656" height="230"&gt;&lt;/a&gt;&lt;br&gt;
Both look the same.&lt;/p&gt;

&lt;p&gt;Let see how both look on an HTML page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MuyglBIb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9bys7trcpjieomjf8z4q.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MuyglBIb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/9bys7trcpjieomjf8z4q.PNG" alt="input code plunker" width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;type="button"&lt;/h5&gt; 

&lt;p&gt;It just creates an HTML button. Nothing else. No button's label and no functionality on click of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OZDJkl1B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/3bjx4srkfx0v7uf8ci0m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OZDJkl1B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/3bjx4srkfx0v7uf8ci0m.PNG" alt="input code plunker" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now after adding &lt;b&gt;value="click"&lt;/b&gt;, we get button's label.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Input&lt;/b&gt; elements of type &lt;b&gt;button&lt;/b&gt; are rendered as simple push buttons, which can be programmed to control custom functionality anywhere on a webpage as required when assigned an event handler function (typically for the click event).&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Input type="button" &lt;/b&gt; elements have no default behavior unlike &lt;b&gt;type="submit"&lt;/b&gt; and &lt;b&gt;type="reset"&lt;/b&gt; have which I will explain in the later part.&lt;/p&gt;

&lt;p&gt;To make input buttons do anything, you have to write JavaScript code to do the work.&lt;/p&gt;

&lt;p&gt;For button &lt;b&gt;type="button"&lt;/b&gt;, it looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q2gd_HJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bzz3qywict9pi58ngcx4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q2gd_HJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bzz3qywict9pi58ngcx4.PNG" alt='button type="button"' width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's add a label.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HTGkqL4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/t5efd1b6ei9olrm6g498.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HTGkqL4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/t5efd1b6ei9olrm6g498.PNG" alt="button label" width="701" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;button&lt;/b&gt; tag does not have &lt;b&gt;value&lt;/b&gt; attribute to set button label.&lt;br&gt;
&lt;b&gt;input&lt;/b&gt; tag does not have a closing tag while the &lt;b&gt;button&lt;/b&gt; tag has a closing tag. &lt;br&gt;
So for those elements that have a closing tag, we can add &lt;b&gt;content&lt;/b&gt; between the opening and the closing tag. &lt;br&gt;
&lt;b&gt;Content&lt;/b&gt; mean any kind like text, image etc.&lt;/p&gt;

&lt;p&gt;What if you put the value attribute in the button tag? Let's see...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_5L0XpIt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/1smlx1i0bejqfngoutrf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_5L0XpIt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/1smlx1i0bejqfngoutrf.PNG" alt="Alt Text" width="731" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing happened because the &lt;b&gt;button&lt;/b&gt; has &lt;b&gt;value&lt;/b&gt; attribute but it is not it's purpose to set button label. The &lt;b&gt;value&lt;/b&gt; attribute specifies the initial value for a &lt;b&gt;button&lt;/b&gt; in a &lt;b&gt;form&lt;/b&gt; tag.(wait for next Part for form)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Difference&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;That's where the difference comes. In the &lt;b&gt;input&lt;/b&gt; tag, you need &lt;b&gt;value&lt;/b&gt; attribute to set label while in &lt;b&gt;button&lt;/b&gt; tag, you do not need any attribute. You can directly put the label between opening and closing button tags.&lt;/p&gt;

&lt;p&gt;Wait... It doesn't make any significant difference in there use. Till now its completely developer's choice. &lt;/p&gt;

&lt;p&gt;BUT what if I ask you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I want a button that has an image in its label and no text? &lt;/li&gt;
&lt;li&gt;I want a button that has an image in its label with a text?
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like this...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNf3aV0L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/4ft6sxpo4do7fvforenu.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNf3aV0L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/4ft6sxpo4do7fvforenu.PNG" alt="button with image" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can see that we have a download button. If you see this is just a &lt;b&gt;button&lt;/b&gt; tag with an &lt;b&gt;image&lt;/b&gt; tag inside it.&lt;/p&gt;

&lt;p&gt;To achieve this with the &lt;b&gt;input&lt;/b&gt; tag, you have to use &lt;b&gt;type="image"&lt;/b&gt; with &lt;b&gt;src&lt;/b&gt; attribute in it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AsZxwcj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/0b32mfxia6hiqu5uso4r.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AsZxwcj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/0b32mfxia6hiqu5uso4r.PNG" alt="Alt Text" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See UI Difference.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_BsB25BV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/f69muvj5hhyer4hkz3kz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_BsB25BV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/f69muvj5hhyer4hkz3kz.PNG" alt="Alt Text" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;input type="image"&lt;/b&gt; do not support &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/image#Value"&gt;value&lt;/a&gt; attirbute. So you cannot add label in input type="image" button&lt;/p&gt;

&lt;p&gt;But we can achieve both image and label in button tag.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Z2Jp2p0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/uxoualvmzh3pf4fid0qa.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Z2Jp2p0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/uxoualvmzh3pf4fid0qa.PNG" alt="Alt Text" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In simple, &lt;b&gt;button&lt;/b&gt; tags can add different types of content but &lt;b&gt;input&lt;/b&gt; can't.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;button&lt;/b&gt; elements are much easier to style than &lt;b&gt;input&lt;/b&gt; elements. You can add inner HTML content (think &lt;b&gt;i, br, or even img&lt;/b&gt;), and use ::after and ::before pseudo-elements for complex rendering.&lt;br&gt;
You can’t use pseudo-classes to style self-closing tags (img, input, hr etc).&lt;/p&gt;

&lt;p&gt;If your buttons are not for submitting form data to a server, be sure to set their type attribute to button. Otherwise, they will try to submit form data and to load the (nonexistent) response, possibly destroying the current state of the document.&lt;/p&gt;

&lt;p&gt;NOTE: If the button tag does not have a type attribute then by default type has "submit" as a value.&lt;/p&gt;

&lt;p&gt;While &lt;b&gt;input&lt;/b&gt; elements of type button are still perfectly valid HTML, the newer &lt;b&gt;button&lt;/b&gt; element is now the favored way to create buttons. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button"&gt;button&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/button"&gt;input&lt;/a&gt; both have a lot of attributes but type attribute is the one that creates confusion. &lt;/p&gt;

&lt;p&gt;Till now we have seen, UI difference between the attribute. But what about the functionality... what will happen on there click?&lt;/p&gt;

&lt;p&gt;Both input and button tag with type="button" attribute only create the idle button. They have no default behavior on click of it.&lt;/p&gt;

&lt;p&gt;Even if you add &lt;b&gt;button type="button"&lt;/b&gt; in the form, it will do nothing. It will not submit the form.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hf2k2E2J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/22pfnczk2v4j2tjhrr05.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hf2k2E2J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/22pfnczk2v4j2tjhrr05.PNG" alt="Alt Text" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Same for &lt;b&gt;input type="button"&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RVQhnB-l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/peoi82cno9gjxgfqpa00.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RVQhnB-l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/peoi82cno9gjxgfqpa00.PNG" alt="Alt Text" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So to do some action on button click just add &lt;b&gt;onclick&lt;/b&gt; on both input and button tag and it will execute the function attached to &lt;b&gt;onclick&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;For more detail on button and input go to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button"&gt;MDN button&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/button"&gt;MDN input&lt;/a&gt;&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;input type="button" and button type="button" both look same in UI as well as in functionality.&lt;/li&gt;
&lt;li&gt;In the button tag, you can add complex content between closing and opening tags. For the input tag, you can't add complex content without using CSS hacks&lt;/li&gt;
&lt;li&gt;Button tag comes with HTML5 and it is a quicker way to create a button. CSS changes are easy on the button tag as compared to the input tag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the end, it depends on your choice. I preferred the button tag. Comment down your choice.&lt;/p&gt;

&lt;p&gt;I hope you guys get something from this post. If you find this useful, please like it, share it, comment down below, debate on it... &lt;/p&gt;

&lt;p&gt;If I missed something, plz point it out. It really helps me and other viewers. Your likes and comments motivate me a lot.&lt;/p&gt;

&lt;h1&gt;Who am I?&lt;/h1&gt;

&lt;p&gt;My name is Anshul Nautiyal. I am a Front-End Developer in Ajio.com&lt;br&gt;
AJIO, a fashion and lifestyle brand, is Reliance Retail's first pan-Indian e-commerce venture. You will get an awesome product at an awesome discount. Do visit. &lt;a href="//www.ajio.com"&gt;AJIO&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;What I do in Ajio?&lt;/h1&gt;

&lt;p&gt;I mostly work on implementing new features in AJIO. Apart from that, I work on performance optimization, code refracting, and try to automate every possible manual work which I and my team are doing every day. I follow the DRY principle both in my code and life.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Stay tuned for part 2...&lt;/b&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Redux with Vanilla JS: Interview Preparation (Part 1)</title>
      <dc:creator>AnshulJS</dc:creator>
      <pubDate>Thu, 20 Feb 2020 12:16:14 +0000</pubDate>
      <link>https://dev.to/anshulnautiyal/redux-with-vanilla-js-interview-preparation-part-1-4m25</link>
      <guid>https://dev.to/anshulnautiyal/redux-with-vanilla-js-interview-preparation-part-1-4m25</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;In this post, we are going to learn how to use &lt;strong&gt;Redux with vanilla JS&lt;/strong&gt; from scratch. I have divided this article into 3 Parts.&lt;/p&gt;

&lt;p&gt;Part 1 will answer these questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is redux?&lt;/li&gt;
&lt;li&gt;If you know about redux then &lt;strong&gt;do you really need it?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Part 2 will answer this question:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If yes, then &lt;strong&gt;how redux work?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Part 3 will answer this question:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You know how it works, then let see &lt;strong&gt;how to use it in JS?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;You should have basic theoretical knowledge of JS.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Let's start.&lt;/em&gt;
&lt;/h3&gt;

&lt;h1&gt;
  
  
  What is redux?
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Redux is a predictable state container for JavaScript apps.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok...Let me close this article. &lt;br&gt;
wait&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
wait&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
wait&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
wait...&lt;/p&gt;

&lt;p&gt;I will explain to you in a layman term with some examples.&lt;/p&gt;

&lt;blockquote&gt;An example is better than a definition.

By Anshul Nautiyal
&lt;/blockquote&gt; 

&lt;p&gt;Let me ask you one question. &lt;strong&gt;&lt;em&gt;How did you manage data in vanilla JS?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your answer is storing local data in a variable and then share it with different parts of an application. &lt;br&gt;
But it will cause a problem because as your codebase increases, managing 100 of variables in a different part of the application is very difficult. right?&lt;/p&gt;

&lt;p&gt;Let use the &lt;strong&gt;TO DO&lt;/strong&gt; web app example to answer this question.&lt;/p&gt;
&lt;h4&gt;
  
  
  index.html
&lt;/h4&gt;

&lt;p&gt;In HTML, we have one &lt;strong&gt;h1&lt;/strong&gt; tag which shows the counter value and a &lt;strong&gt;button&lt;/strong&gt; tag to increment the &lt;strong&gt;h1&lt;/strong&gt; value.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 id="counter"&amp;gt;&amp;lt;h1&amp;gt;
Add
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  index.js
&lt;/h3&gt;

&lt;p&gt;Let write some javascript code to make it work. Don't forget to add index.js file in index.html&lt;/p&gt;

&lt;p&gt;If you see the &lt;strong&gt;h1&lt;/strong&gt; tag in the index.html file, it does not have an initial value.&lt;br&gt;
So, let first set it in JS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sh_d84v4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/44zvnc0avpipl0dq9qad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sh_d84v4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/44zvnc0avpipl0dq9qad.png" alt="Source Code Image" width="800" height="216"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
NOTE:
I add script tag at the end of body tag in the index.html file because in this case, first I want complete body is rendered in a browser and then index.js file should load. 

If I add script tag below the title tag then I will get error in console: 
cannot set property 'innerHTML' of null Why? Comment down below.
&lt;/blockquote&gt;


&lt;p&gt;In the index.js file, I create an IIFE (Immediately-Invoked Function Expression). This function executes immediately after it’s created. In this case, as soon as index.js file loads IIFE function starts executing.&lt;br&gt;&lt;br&gt;
Then it set &lt;strong&gt;0&lt;/strong&gt; value in the &lt;strong&gt;h1&lt;/strong&gt; tag which is an initial value.&lt;br&gt;&lt;br&gt;
You can store initial value in some variable and then assign it like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--52kJ8jyt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/aktcfz72wftb0p4smm2k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52kJ8jyt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/aktcfz72wftb0p4smm2k.png" alt="Source Code Image" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the catch. &lt;br&gt;
I have stored data/state in a variable called &lt;strong&gt;initialValue&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;Both &lt;b&gt;data&lt;/b&gt; and &lt;b&gt;state&lt;/b&gt; are the same things. I heard &lt;b&gt;state&lt;/b&gt; term when I was learning the React library where we store local data/state in class and function. Nothing fancy. Don't get confused.&lt;/blockquote&gt;

&lt;p&gt;I will use &lt;strong&gt;state&lt;/strong&gt; to point the data we store in our index.js file.&lt;/p&gt;

&lt;p&gt;Now back to the point, remember this thing that I have stored state in &lt;strong&gt;initialValue&lt;/strong&gt; variable. But what if I want to share this &lt;strong&gt;initialValue&lt;/strong&gt; state in some other file. Either I have to export it or  I have to make it global. &lt;br&gt;
Shoot me but I will not use or recommend for global use. Global has its own consequences. For example, what if the initial counter value should be 0 and since it is global, someone changes it to some other value which is wrong.&lt;/p&gt;

&lt;p&gt;So you have to export it but then exporting it to thousands file and then managing the same value in all files is troublesome (causing difficulty). &lt;/p&gt;

&lt;p&gt;So we came back again to use the global variable.&lt;/p&gt;

&lt;p&gt;Let see the advantage and disadvantage of using a global variable in our application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantage:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;It can be easily accessed in all the files.&lt;/li&gt;
&lt;li&gt;The same value will be there throughout the application. So if we change the value in file1 then the file2 will get the updated value.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Disadvantage:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Since global variables are easily accessible in all files, there are chances that if someone tries to change the local variable that have the same name as a global variable then it will show the change effect in all the places. This small mistake can cause a lot of problems in the entire application. For example, if &lt;strong&gt;initialValue&lt;/strong&gt; variable is globally declared and someone mistakenly changes &lt;strong&gt;initialValue&lt;/strong&gt;'s value from number to string then it will show the wrong value in the all place where it is being used.&lt;/li&gt;
&lt;li&gt;There is no mechanism of how to update or restrict the scope of global value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So in the end, we came to the conclusion that managing the state with global scope is fine if we can put some restrictions on its update/access.&lt;br&gt;
If we somehow do that we can use the global variable. Don't shoot me, I'm in the mood to use global variables.&lt;/p&gt;

&lt;p&gt;Now you can see that managing state in our small application is challenging if its codebase increases with time. &lt;/p&gt;

&lt;p&gt;Here comes Redux to the rescue.&lt;/p&gt;

&lt;p&gt;In simple terms, &lt;strong&gt;Redux&lt;/strong&gt; is a state management 3rd party javascript library that helps you to manage data for your large application in more efficient and elegant ways.&lt;/p&gt;

&lt;p&gt;The concept behind redux is to have one very very big global Javascript Object that will manage the data for our whole application.&lt;/p&gt;

&lt;p&gt;Now you know what is Redux and Why you should use it?&lt;/p&gt;

&lt;p&gt;Some of you may have doubts that if I can write my own logic to handle global JavaScript Object then I did not need redux. I agree with you but here is the point, now you have 2 challenges:- manage application data and manage/modify the logic of handling global JS object time to time and then test it for thousands of scenarios. &lt;br&gt;
Obviously, No one wants to take this much of headache. It is better to let redux handle state management for your application and we just focus on getting the right data to our application.&lt;/p&gt;

&lt;p&gt;How Redux handles and manipulates this big data store will be answered in the next post (Part 2). &lt;/p&gt;

&lt;h1&gt;
  
  
  Who am I?
&lt;/h1&gt;

&lt;p&gt;My name is Anshul Nautiyal. I am a Front-End Developer in Ajio.com&lt;br&gt;
AJIO, a fashion and lifestyle brand, is Reliance Retail's first pan-Indian e-commerce venture. You will get an awesome product at an awesome discount. Do visit. &lt;a href="https://www.ajio.com"&gt;AJIO&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What I do in Ajio?
&lt;/h1&gt;

&lt;p&gt;I mostly work on implementing new features in AJIO. Apart from that, I work on performance optimization, code refracting and try to automate every possible manual work which I and my team are doing every day. I follow the &lt;strong&gt;DRY principle&lt;/strong&gt; both in my code and life.&lt;/p&gt;

&lt;p&gt;Guys give thumbs up if you like it, share it, and leave a comment down below if you like it or not. Share your valuable feedback to improve this blog.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>redux</category>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
