<?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: Rajat M</title>
    <description>The latest articles on DEV Community by Rajat M (@rajatm544).</description>
    <link>https://dev.to/rajatm544</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%2F354169%2Fafab7ff9-70ff-4b29-b4bd-1287aefc9db0.jpg</url>
      <title>DEV Community: Rajat M</title>
      <link>https://dev.to/rajatm544</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajatm544"/>
    <language>en</language>
    <item>
      <title>Implement 5 Sorting Algorithms using JavaScript.</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 20 Sep 2020 18:44:20 +0000</pubDate>
      <link>https://dev.to/rajatm544/implement-5-sorting-algorithms-using-javascript-1fc3</link>
      <guid>https://dev.to/rajatm544/implement-5-sorting-algorithms-using-javascript-1fc3</guid>
      <description>&lt;p&gt;Most languages have a built-in method which serves the purpose of trying to sort a bunch of data. The common tendency amongst most developers, especially those who are just beginning their journey, might be to choose this path and avoid writing their own implementation. But, this &lt;strong&gt;can end up having unforeseen repercussions in terms of performance&lt;/strong&gt;. Therefore, it is better to go with a sorting technique that is best suited for your current requirement.&lt;/p&gt;

&lt;p&gt;The first 3 sorting algorithms that I cover in this article, have an &lt;strong&gt;average time complexity of O(n²)&lt;/strong&gt;. These are ones which are fairly popular, and are much more intuitive in their approach to sort data.&lt;/p&gt;

&lt;p&gt;The other 2 have an &lt;strong&gt;average time complexity of O(n*log n)&lt;/strong&gt;, and can be bit tricky to comprehend if you have no prior knowledge of recursion. So, I would suggest that you go through &lt;a href="https://www.freecodecamp.org/news/recursion-demystified-99a2105cb871/" rel="noopener noreferrer"&gt;this article&lt;/a&gt; to understand how recursion works.&lt;/p&gt;

&lt;p&gt;In the following sections, I shall give you a brief explanation as to how that particular algorithm goes about sorting data. Then, I give you some pseudocode in case you wish to go ahead and try to implement that algorithm on your own. Finally, I provide a gist for my implementation of the algorithm. I would suggest that you understand the pseudocode before diving into the gist, as that will help you grasp the use case for each algorithm better.&lt;/p&gt;




&lt;p&gt;Let’s get started with &lt;strong&gt;Bubble Sort&lt;/strong&gt;, shall we. The space complexity for the algorithm is O(1) and the average time complexity is O(n²).The pseudocode is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Start iterating through the array, comparing 2 elements at a time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Swap them as required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At the end of first pass, the largest number has bubbled to the last index of the array, so ignore the last index in the next pass.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Continue these passes until the array is sorted.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ARfHrEI8NAlfbfhduORRcdg.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ARfHrEI8NAlfbfhduORRcdg.png" alt="An illustration to understand how bubble sort works"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code for the implementation in JS is as follows:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that the second implementation is slightly optimized to handle an array that is almost sorted.&lt;/p&gt;




&lt;p&gt;The next sorting algorithm which has a time complexity of O(n²) is &lt;strong&gt;Insertion Sort&lt;/strong&gt;, it also has a space complexity of O(1). This is most useful when there is a scenario wherein you are receiving a series of numbers in real time, and need them in a sorted array.&lt;/p&gt;

&lt;p&gt;The main concept to understand when using this technique is that, there is a &lt;strong&gt;portion of the array that is always sorted&lt;/strong&gt; and a section that remains unsorted.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Start by comparing the 2nd element with the 1st element, swap if necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Iterate through the rest of the array. Then, for each element, iterate through the &lt;strong&gt;&lt;em&gt;sorted portion&lt;/em&gt;&lt;/strong&gt; of the array, and &lt;strong&gt;&lt;em&gt;insert&lt;/em&gt;&lt;/strong&gt; this element where it needs to be, by making comparisons.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep doing this until all the elements have been inserted into their correct positions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AX78qSPfXtjwMzPmUvv_4nQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AX78qSPfXtjwMzPmUvv_4nQ.png" alt="An illustration to understand how insertion sort works"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code for the same is as shown below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;Selection Sort&lt;/strong&gt; is the last sorting algorithm to have a time complexity of O(n²), included in this article. The space complexity is the same as the previous two techniques i.e, O(1). The pseudocode for this algorithm is as follows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Assume that the &lt;strong&gt;first element is the smallest&lt;/strong&gt;. (Or largest, if sorting in descending order).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Find the &lt;strong&gt;minimum value&lt;/strong&gt; from the array &lt;strong&gt;and swap&lt;/strong&gt; this with the first element of the array. This completes one pass, wherein the smallest element of the array is now at the 0th index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat this procedure for the rest of the array elements, but for the next pass do not compare the element we just placed at the 0th index.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is usually not that useful in most situations, but still helps a beginner grasp the concepts of implementing an algorithm to solve a problem.&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A33hTSw7_SQNJrs2xZsdGiA.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A33hTSw7_SQNJrs2xZsdGiA.png" alt="An illustration to understand how selection sort works."&gt;&lt;/a&gt;&lt;br&gt;
My implementation is as follows. Note that the sorted array is built up from the 0th index.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;You may have noticed that it is quite difficult to get a performant sorting algorithm using these techniques. Hence, in order to have an algorithm that is better than O(n²) in terms of time complexity, we have to use recursion.&lt;/p&gt;

&lt;p&gt;The next 2 techniques can seem less intuitive at first go. So do read the pseudocode before you jump to the code, in order to make sense of the procedure followed!&lt;/p&gt;

&lt;p&gt;Both of them have an &lt;strong&gt;average time complexity of O(n * log n).&lt;/strong&gt; Their space complexities varies depending on the technique.&lt;/p&gt;




&lt;p&gt;Let’s take a look at how &lt;strong&gt;merge sort&lt;/strong&gt; is able to use recursion to implement an algorithm with a better time complexity.&lt;/p&gt;

&lt;p&gt;The main concept here is that &lt;strong&gt;an array with size 0 or 1 is inherently sorted&lt;/strong&gt;. This means that if we are able to split our array into smaller subarrays of size 0 or 1, and merge them correctly, we have sorted our array!&lt;/p&gt;

&lt;p&gt;So there are two things that we need to do before we can implement merge sort. We need to find a way to &lt;strong&gt;divide an array into halves continuously&lt;/strong&gt;, until we end up with arrays of size 0 or 1. Then, we &lt;strong&gt;merge them in a way that results in a larger (but still sorted) array&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The pseudocode to continuously divide an array, and end up with a bunch of arrays of size 0 or 1, is as follows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  We use recursion to do this. Use &lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice" rel="noopener noreferrer"&gt;slice()&lt;/a&gt;&lt;/strong&gt; to halve the array, and do this until the &lt;strong&gt;base case of arr.length ≤ 1&lt;/strong&gt; is reached.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s tackle the issue of merging two arrays (of size≤1) such that we end up with a sorted array.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Start by making an empty array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compare the first elements of the 2 subarrays, and &lt;strong&gt;push the smaller of the two, to the the new array&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Suppose 1st element of 1st array is smaller, then push that to the new array. Now compare the &lt;strong&gt;2nd element of the first array&lt;/strong&gt; to the &lt;strong&gt;1st element of the 2nd array&lt;/strong&gt;, and so on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If we have exhausted the array elements in any of the 2 subarrays, then &lt;strong&gt;just push the other subarray to the new array&lt;/strong&gt; we had created.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See the image below to see how this technique needs to work.&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2At7SwqcHNrswPUjeNELPkzg.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2At7SwqcHNrswPUjeNELPkzg.png" alt="Illustration for merge sort. **Note:** The middle element is colored red."&gt;&lt;/a&gt;&lt;em&gt;&lt;strong&gt;Note:&lt;/strong&gt; The middle element is colored red.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The code for the merge sort algorithm is as follows. Note the &lt;strong&gt;use of helper function&lt;/strong&gt; to implement the merging of 2 subarrays, and it is pretty evident that the &lt;strong&gt;space complexity for this algorithm is O(n)&lt;/strong&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;Lastly, let us see how &lt;strong&gt;quick sort&lt;/strong&gt; justifies its name and goes about sorting an array.&lt;/p&gt;

&lt;p&gt;It works by &lt;strong&gt;choosing a pivot element&lt;/strong&gt;, and making sure that all the elements &lt;strong&gt;to the left of the pivot element is less&lt;/strong&gt; than the pivot(not necessarily sorted, they just need to be less than the pivot) and that all the &lt;strong&gt;elements to the right of the pivot are all greater&lt;/strong&gt; than it.&lt;/p&gt;

&lt;p&gt;The only 2 tasks we need to do in order to implement quick sort’s algorithm is to &lt;strong&gt;correctly identify the index for the pivot&lt;/strong&gt; and place the pivot element at that index. Initially, we assume the pivot to any element in the array, in this example I shall consider the 0th element to be the initial pivot.&lt;/p&gt;

&lt;p&gt;The pseudocode to correctly return the index for the pivot element is as follows. Note that this is also called the &lt;strong&gt;partition function&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Choose a pivot, &lt;strong&gt;store its index&lt;/strong&gt; in a variable, let’s say &lt;code&gt;pivotIndex&lt;/code&gt;. Loop through the array, if the current element is less than than the pivot, then increment the &lt;code&gt;pivotIndex&lt;/code&gt;, and swap the current element with the element present at the new &lt;code&gt;pivotIndex&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After one iteration through the array, &lt;strong&gt;swap&lt;/strong&gt; the pivot with the element present at the &lt;code&gt;pivotIndex&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you have a helper function to do the above task, we need to &lt;strong&gt;recursively place all the pivot elements in their correct positions&lt;/strong&gt;. The pseudocode to so that is as follows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Assume &lt;code&gt;left&lt;/code&gt; indicates the start of a subarray, and &lt;code&gt;right&lt;/code&gt; indicates the last index of the subarray.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Do the following only if the &lt;code&gt;left&lt;/code&gt; pointer is at a lesser index than the &lt;code&gt;right&lt;/code&gt; pointer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Start by calling the &lt;strong&gt;partition()&lt;/strong&gt; on the entire array by defaulting the &lt;code&gt;left&lt;/code&gt; and &lt;code&gt;right&lt;/code&gt; pointers to the &lt;strong&gt;first&lt;/strong&gt; and &lt;strong&gt;last&lt;/strong&gt; element of the array respectively.&lt;/li&gt;
&lt;li&gt;  Then store the return value in the &lt;code&gt;pivotIndex&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  Use this to recursively call &lt;strong&gt;quickSort()&lt;/strong&gt; with the same array, but from &lt;code&gt;left&lt;/code&gt; &lt;strong&gt;up until (pivotIndex - 1)&lt;/strong&gt;, for the &lt;code&gt;left&lt;/code&gt; part of the array.&lt;/li&gt;
&lt;li&gt;  For the &lt;code&gt;right&lt;/code&gt; part of the array, call &lt;strong&gt;quickSort()&lt;/strong&gt; again, with the same array, but from (&lt;strong&gt;pivotIndex + 1) upto &lt;code&gt;right&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the base case becomes invalid, it means that &lt;code&gt;left&lt;/code&gt; equals &lt;code&gt;right&lt;/code&gt;, so we return the array.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The video shows a visualization of quick sort algorithm. The pivot elements are colored yellow.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/459942910/fa95650df0" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;br&gt;
The code for implementing quick sort in JavaScript is as follows. Note that the &lt;strong&gt;space complexity is O(log n)&lt;/strong&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;Now that you know how to implement these 5 sorting algorithms, the next step is to understand which technique works best for the situation you find yourself in. To see some regular use cases, you can checkout &lt;a href="https://www.geeksforgeeks.org/when-to-use-each-sorting-algorithms/" rel="noopener noreferrer"&gt;this article&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Understand Life Cycle Methods in React.js</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 13 Sep 2020 18:30:13 +0000</pubDate>
      <link>https://dev.to/rajatm544/understand-life-cycle-methods-in-react-js-5a00</link>
      <guid>https://dev.to/rajatm544/understand-life-cycle-methods-in-react-js-5a00</guid>
      <description>&lt;p&gt;To build a project using React, the first step is to figure out the various Components that are required to bring your project to life! Once you are able to visualize the client-side of your project as a &lt;strong&gt;collection of Components&lt;/strong&gt;, half the battle is won. So it is fair to say that Components form the crux of any React application.&lt;/p&gt;

&lt;p&gt;But how does a collection of Components end up becoming a &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/SPA"&gt;single page application&lt;/a&gt;? This is no different to the way &lt;em&gt;every single&lt;/em&gt; website is rendered by your browser i.e, by &lt;strong&gt;creating a DOM&lt;/strong&gt;. But in case of React, the Components are first woven into a &lt;a href="https://reactjs.org/docs/faq-internals.html"&gt;&lt;strong&gt;Virtual DOM&lt;/strong&gt;&lt;/a&gt; and only the necessary modifications are made to the &lt;em&gt;real&lt;/em&gt; DOM. In order to do this, React must constantly keep track of every Component built for the project, and this is where we come across the &lt;strong&gt;life cycle of a Component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The following article provides a more elaborate explanation of how a browser renders a web page after creating the DOM. You can check it out if you need some more clarification!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/jspoint/how-the-browser-renders-a-web-page-dom-cssom-and-rendering-df10531c9969" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m12Oy8bK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2AB4PQwnTacbDmtJgKYY7CzA.jpeg" alt="Uday Hiwarale"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/jspoint/how-the-browser-renders-a-web-page-dom-cssom-and-rendering-df10531c9969" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How the browser renders a web page? — DOM, CSSOM, and Rendering | by Uday Hiwarale | JsPoint | Medium&lt;/h2&gt;
      &lt;h3&gt;Uday Hiwarale ・ &lt;time&gt;Oct 4, 2020&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;A Component undergoes 3 phases in its life cycle. Think of it as milestones along the course of a Component’s life.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mounting&lt;/strong&gt;: This is the stage where the &lt;em&gt;Component is inserted into the DOM&lt;/em&gt;. This phase is accounted for using the &lt;strong&gt;componentDidMount()&lt;/strong&gt; method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Updating&lt;/strong&gt;: This is the stage in which the &lt;em&gt;Component’s state and props can change&lt;/em&gt;, leading to the process of re-rendering the Component with the updated state/props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unmounting:&lt;/strong&gt; This is the final stage of the Component’s life, in which it is &lt;em&gt;removed from the DOM&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that sometimes there is another stage which is considered even before a Component is &lt;strong&gt;mounted&lt;/strong&gt;. This is called the &lt;strong&gt;Initialization&lt;/strong&gt; stage, where the Component’s initial state is set. Hence, it is common to see images that depict 4 stages in a Component’s life cycle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lhYVT0FF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A4YjVu-tQtQc2Esw8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lhYVT0FF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A4YjVu-tQtQc2Esw8.png" alt="4 phases of a Component’s life cycle" width="605" height="547"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Now let us dive a little deeper into the life cycle methods which can be applied to a Component &lt;strong&gt;at various phases&lt;/strong&gt;. Note that I am deliberately excluding certain deprecated methods.&lt;/p&gt;

&lt;p&gt;Before we start learning about the different methods available, it’s better to understand the role that they play.&lt;/p&gt;

&lt;p&gt;It is very straight forward too! These methods are like checkpoints along the way. They are invoked &lt;strong&gt;only&lt;/strong&gt; at the very specific phases of a Component’s life cycle. This way, we have &lt;strong&gt;more control&lt;/strong&gt; over a Component’s behavior, which in turn gives us a more flexible approach to building the UI using those Components!&lt;/p&gt;

&lt;p&gt;Take a look at the image below, which shows the various methods and the points at which they are invoked.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qF18RisO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2778/0%2AB6RwjaGX9zy1_9yy.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qF18RisO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2778/0%2AB6RwjaGX9zy1_9yy.jpeg" alt="Illustration for understanding the use of life cycle methods" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Let us go over some of the most commonly used life cycle methods, along with examples.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;constructor():&lt;/strong&gt; This is used only if you have a &lt;strong&gt;class-based&lt;/strong&gt; Component and it serves the purpose of &lt;strong&gt;initializing the state&lt;/strong&gt; of a Component. In case of functional Components, the &lt;strong&gt;useState()&lt;/strong&gt; hook is used to do the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider an example in which you are creating a Component to store Todo tasks.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;ComponentDidMount()&lt;/strong&gt;: As seen from the image in the previous section, this is invoked &lt;strong&gt;after a Component is inserted into the DOM for the first time&lt;/strong&gt;. This has a variety of uses, one of which can be to update state after a Component is mounted, like the example shown below.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;render()&lt;/strong&gt;: This is the method that is responsible for &lt;strong&gt;inserting a Component into the DOM&lt;/strong&gt;. This is invoked every time a Component’s state/props is updated.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;Now let us take a look at the life cycle methods which are invoked during the &lt;strong&gt;updating&lt;/strong&gt; phase of a Component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;shouldComponentUpdate():&lt;/strong&gt; This is invoked &lt;strong&gt;immediately after a Component’s state or props is updated&lt;/strong&gt;. Although most changes are dealt with using the componentDidUpdate() method, this is often a more immediate way of dealing with the change. To take a look at a possible scenario where this comes in handy, you can go through &lt;a href="https://www.freecodecamp.org/news/react-shouldcomponentupdate-demystified-c5d323099ef6/"&gt;this article&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;componentDidUpdate()&lt;/strong&gt;: This is the method invoked &lt;strong&gt;after re-rendering an updated Component&lt;/strong&gt;. This method can give you the information about a Component’s &lt;strong&gt;previous state&lt;/strong&gt; and &lt;strong&gt;previous props.&lt;/strong&gt; A fair warning to give before you start using this method is to &lt;strong&gt;never directly set the state of a Component&lt;/strong&gt; within it. Doing that will change the Component’s state, futher triggering a componentDidUpdate() and so on.&lt;br&gt;
&lt;a href="https://www.newline.co/@dmitryrogozhny/using-componentdidupdate-in-react--f037b5aa"&gt;This article&lt;/a&gt; provides some safe use cases for this life cycle method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;getSnapshotBeforeUpdate():&lt;/strong&gt; This is used only when the developer requires more data &lt;strong&gt;about the DOM before the Component was updated and re-rendered&lt;/strong&gt;. Although this is seldom used, the &lt;a href="https://linguinecode.com/post/what-is-react-getsnapshotbeforeupdate"&gt;this article&lt;/a&gt; does a very good job of providing an explanation for an important use case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;getDerivedStateFromProps():&lt;/strong&gt; Again, this is a method that is seldom used. I have never come across a scenario which required the use of this specific method, and the team at &lt;a href="https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html"&gt;React seems to agree&lt;/a&gt;!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Finally, the only method to deal with the unmounting of a Component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;componentWillUnmount():&lt;/strong&gt; This is invoked &lt;strong&gt;just before a Component is removed&lt;/strong&gt; from the DOM. This is where you can perform any cleanups that need to be done such as invalidating timers, canceling network requests, removing event listeners, and so on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the methods that you are most likely to come across. But as I mentioned earlier, I have omitted certain methods that are deprecated or are set to be deprecated in the very near future. So, in case you run into a legacy system which uses some of the deprecated life cycle methods, you may need to do a bit of Googling!&lt;/p&gt;

&lt;p&gt;Lastly, in case you are working with a functional Component, and are having trouble with implementing some of the methods discussed, you can go through the following article.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@divyabiyani26/react-useeffect-a-hook-to-introduce-lifecycle-methods-in-functional-components-e7ec52897188" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pWX2BIz---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/2%2Ah4l8_rZePSDxDsrwLnJGAw.jpeg" alt="Divya Biyani"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@divyabiyani26/react-useeffect-a-hook-to-introduce-lifecycle-methods-in-functional-components-e7ec52897188" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;React useEffect : A hook to introduce lifecycle methods in functional components | by Divya Biyani | Medium&lt;/h2&gt;
      &lt;h3&gt;Divya Biyani ・ &lt;time&gt;Feb 9, 2021&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>react</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>What Are RESTful Routes and How to Use Them?</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 06 Sep 2020 17:56:55 +0000</pubDate>
      <link>https://dev.to/rajatm544/what-are-restful-routes-and-how-to-use-them-1a28</link>
      <guid>https://dev.to/rajatm544/what-are-restful-routes-and-how-to-use-them-1a28</guid>
      <description>&lt;p&gt;Chances are that you have already heard about REST APIs even before you stumbled upon this article. But maybe you never fully understood what that meant, or as to why it is used so frequently. The crux of the matter is that, it is just &lt;strong&gt;a set of constraints in API design&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But why would this be necessary? Can’t an API endpoint have any pattern a developer wishes to keep? After all, an API is just an interface for data transfer, it would work regardless of the pattern of the server requests, as long as it correctly matches the API design. Right?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In case you had this dialogue with yourself, &lt;em&gt;you would be right&lt;/em&gt;. But you would also have to deal with the &lt;strong&gt;server security issues&lt;/strong&gt;, &lt;strong&gt;portability issues&lt;/strong&gt;, &lt;strong&gt;platform-compatibility issues&lt;/strong&gt; and &lt;strong&gt;scalability issues&lt;/strong&gt; among other things! So it is a wiser choice to choose RESTful design for your API. Apart from all these advantages, REST APIs can provide a sanity check for most developers since it makes it easier to collaborate.&lt;/p&gt;

&lt;p&gt;I hope that I have managed to convince you that RESTful routing is essential, now let us see what the fuss is all about!&lt;/p&gt;




&lt;p&gt;Let us first understand why it is called RESTful routing in the first place. Note that ‘RESTful routes’ and ‘REST API endpoints’ are used interchangeably when trying to describe the concept. Here REST is an acronym for &lt;strong&gt;Representational State Transfer&lt;/strong&gt;. Before we can understand what this means, it’s important that you have some basic understanding of how clients and servers communicate.&lt;/p&gt;

&lt;p&gt;The gist of the client-server architecture is that a browser (client) is able to send multiple requests to the server. Here, the server needs no information regarding the client itself, hence it also termed as a &lt;strong&gt;stateless transaction&lt;/strong&gt; of data. This implies that the server will send a response corresponding to the &lt;strong&gt;current state&lt;/strong&gt; of the client. RESTful design leverages this concept to simplify API design!&lt;/p&gt;

&lt;p&gt;TL;DR - it is called RESTful design because the &lt;strong&gt;client initiates a change in its state through a server request sent using a representation of its current state.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To simplify it further, RESTful routes are a standard set of rules that are used to carry out the CRUD operations, by using a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods"&gt;set of HTTP verbs&lt;/a&gt; to make server requests.&lt;/p&gt;

&lt;p&gt;If you feel like you could use some more information regarding the client-server architecture, you can find it in the following article.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@rachna3singhal/stateless-over-stateful-applications-73cbe025f07" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--haO1R4GN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2AsyS_qdu0BRhlEeFjFpgOYQ%402x.jpeg" alt="Rachna Singhal"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@rachna3singhal/stateless-over-stateful-applications-73cbe025f07" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Stateless Over Stateful Applications | by Rachna Singhal | Medium&lt;/h2&gt;
      &lt;h3&gt;Rachna Singhal ・ &lt;time&gt;Apr 8, 2019&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;If the previous section seemed a tad bit confusing, it’s completely fine to ignore the unnecessary details, and just learn about the implementation alone, as long as you understand the steps involved in the actual API design.&lt;/p&gt;

&lt;p&gt;In a REST API, there are just seven endpoints to perform any of the CRUD operations. They all use a HTTP verb to perform server requests based on the operation needed. An acronym that can help you remember all these routes, in the order that they need to be declared is &lt;strong&gt;INCSEUD&lt;/strong&gt; (ink-say-ud).&lt;/p&gt;

&lt;p&gt;Consider an example wherein you are creating a CRUD application by using MongoDB to maintain a record of all the dogs you have (why not). Refer the table to take a look at the 7 RESTful routes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9AE-ba5D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2270/1%2AE4WwbdA-NSJJimYZA9r6Cg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9AE-ba5D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2270/1%2AE4WwbdA-NSJJimYZA9r6Cg.png" alt="A table illustrating the different RESTful API endpoints" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Index:&lt;/strong&gt; This is the API endpoint that will &lt;strong&gt;return all documents&lt;/strong&gt; stored in a particular collection. In order to make use of this endpoint, you will need to make a GET request to the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;New:&lt;/strong&gt; This is an endpoint that is used to &lt;strong&gt;display a form&lt;/strong&gt;, which is used to fill the data as per the &lt;a href="https://docs.mongodb.com/realm/mongodb/document-schemas/#:~:text=to%20the%20schema.-,Document%20Schema%20Configuration,each%20document%20in%20a%20collection."&gt;Document Schema&lt;/a&gt;. Note that this route &lt;strong&gt;does not add new documents to the collection yet&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt;: This is the route that is meant to &lt;strong&gt;add a new document to the collection&lt;/strong&gt;. You would need to make a POST request to send data to this API endpoint.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Show&lt;/strong&gt;: This is the endpoint that &lt;strong&gt;returns a particular document&lt;/strong&gt; in JSON format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; This will &lt;strong&gt;display a form to update a particular document&lt;/strong&gt;. You can use the SHOW route to fetch a particular document’s data and use that to pre-populate the form fields. Note that this will not make any changes to the collection yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; This is used to &lt;strong&gt;update the document of a particular id&lt;/strong&gt;, by making a PUT request to the server. This will not return the updated document, instead it is common to redirect a user to the SHOW page of the particular document.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Destroy:&lt;/strong&gt; This will &lt;strong&gt;delete a particular document&lt;/strong&gt; from the collection, by making a DELETE request to the server. After this process, it is common to redirect a user to the INDEX page.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In case you aren’t familiar with MongoDB or the Mongoose ODM, you can go through &lt;a href="https://www.freecodecamp.org/news/introduction-to-mongoose-for-mongodb-d2a7aa593c57/"&gt;this article&lt;/a&gt;, which gives an introduction to the topic.&lt;/p&gt;

&lt;p&gt;The best way to grasp the importance of these RESTful routes, is by building a CRUD application using them. To do that using Express.js and MongoDB, you can take a look at the following article.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@dinyangetoh/how-to-build-simple-restful-api-with-nodejs-expressjs-and-mongodb-99348012925d" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HYWQy5Nj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2AmxULtv3c30vy9-HyS3L7Rg.jpeg" alt="David Inyang-Etoh"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@dinyangetoh/how-to-build-simple-restful-api-with-nodejs-expressjs-and-mongodb-99348012925d" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How To Build Simple RESTful API With NodeJs, ExpressJs And MongoDb | by David Inyang-Etoh | Medium&lt;/h2&gt;
      &lt;h3&gt;David Inyang-Etoh ・ &lt;time&gt;Jul 11, 2019&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In case you prefer a video tutorial to better understand the workflow involved in creating a REST API using Express and Mongo, you can check out this video from Traversy Media.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/eB9Fq9I5ocs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That’s it! You now know what a RESTful API means and what the 7 RESTful routes are. You also have a few resources to go ahead and build one yourself. It is a very important concept in full stack development, but all you need to build is a single CRUD application in order to learn it thoroughly!&lt;/p&gt;

&lt;p&gt;Lastly, consider going through &lt;a href="https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/"&gt;this article&lt;/a&gt; to take a look at some best practices for building a REST API of your own.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>rest</category>
      <category>api</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Are Service Workers and How to Use Them?</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 30 Aug 2020 19:16:32 +0000</pubDate>
      <link>https://dev.to/rajatm544/what-are-service-workers-and-how-to-use-them-4j55</link>
      <guid>https://dev.to/rajatm544/what-are-service-workers-and-how-to-use-them-4j55</guid>
      <description>&lt;p&gt;What is a web application? An app that can be accessed &lt;em&gt;only&lt;/em&gt; through a browser? An app that cannot replicate the rich offline experience that a native application can provide? Or, an app that requires a constant internet connection to work properly?&lt;/p&gt;

&lt;p&gt;In case you agree with any of these answers, this article will be a huge revelation for you! But as most of us already know, a modern web application can do so much more than just running a few scripts on the browser to display HTML.&lt;/p&gt;

&lt;p&gt;It can cache content so that it can be accessed offline. It can be installed just like any native app, to provide all the rich experiences of a native app. It can &lt;a href="https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web"&gt;push notifications&lt;/a&gt; to its users and also provide a periodic &lt;a href="https://developers.google.com/web/updates/2015/12/background-sync"&gt;background sync&lt;/a&gt; for data backup!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;This is where service workers come into the picture!&lt;/strong&gt; Put simply, a service worker is a JavaScript file used to cache certain assets of your application.&lt;/p&gt;

&lt;p&gt;It works by allowing a developer to control how network requests are handled by the app. Before we start with the code involved, let us learn about the &lt;strong&gt;lifecycle of a service worker&lt;/strong&gt;, which will make it easier to understand how an app’s assets can be stored in cache.&lt;/p&gt;

&lt;p&gt;Note that we make use of ES6 Promises to implement service workers, and in case you aren’t aware of the topic, you can go through this article I had posted a while back.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/rajatm544" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5W8-gGje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.dev.to/cdn-cgi/image/width%3D150%2Cheight%3D150%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto/https%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Fuser%252Fprofile_image%252F354169%252Fafab7ff9-70ff-4b29-b4bd-1287aefc9db0.jpg" alt="rajatm544"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/rajatm544/what-are-javascript-promises-4mp6" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;What Are JavaScript Promises?&lt;/h2&gt;
      &lt;h3&gt;Rajat M ・ Aug 23 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#es6&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;There are a few steps involved in getting a service worker up and running, and they are referred to as the life cycle of the service worker. This image displays the simplified version of the various stages involved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2EJIdyaK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A0V7Lgqku2M4TZbmU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2EJIdyaK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A0V7Lgqku2M4TZbmU.png" alt="Life cycle of a typical service worker" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that each step is asynchronous. Here, the 3 major &lt;em&gt;milestones&lt;/em&gt; are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Installing a service worker&lt;/strong&gt;: This includes &lt;strong&gt;registering&lt;/strong&gt; a worker. Doing so will in turn cause the browser to start installing the service worker in the background. In this step, most of the static files are cached successfully.
In case you are curious as to where you can find the cached assets, open the &lt;strong&gt;Application&lt;/strong&gt; tab of the Chrome &lt;strong&gt;DevTools&lt;/strong&gt;, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SZA5I32A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AHSuAmQb0G-vp8t_lFWvcOg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SZA5I32A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AHSuAmQb0G-vp8t_lFWvcOg.png" alt="The cached files will be seen in the Application tab as shown here" width="539" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Activating the service worker&lt;/strong&gt;: This step is mostly used to delete an older version of the service worker. You would want to do this when you have updated some assets of your app, and you want the service worker to cache the newer assets*&lt;em&gt;,&lt;/em&gt;* after deleting the older ones.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fetching the required content from cache&lt;/strong&gt;: This step will be responsible for fetching the cached assets, in order to allow an app to function offline. This step usually takes place whenever a network request is made and the required data has already been cached.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;We now know that a service worker has to follow certain steps before it can help us convert our web app into a &lt;a href="https://web.dev/progressive-web-apps/"&gt;Progressive Web Application&lt;/a&gt;. So let’s start writing some code to do the same.&lt;/p&gt;

&lt;p&gt;Start by creating a file called &lt;strong&gt;worker.js&lt;/strong&gt; or &lt;strong&gt;sw.js&lt;/strong&gt; in the root of you project. It is easier if your index HTML file is at the same level as your service worker file.&lt;/p&gt;

&lt;p&gt;First, you will need to &lt;strong&gt;register&lt;/strong&gt; a service worker. You can choose to do it in a separate file and link it to the &lt;strong&gt;index.html&lt;/strong&gt; (Or, the main HTML file in the root of your project). But you will often see a service worker being registered in the HTML file itself, within a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;

if ('serviceWorker' in navigator) {
    window.addEventListener("load", () =&amp;gt; {
    navigator.serviceWorker.register('/sw.js')
    .then(reg =&amp;gt; console.log("Service worker registered"))
    .catch(err =&amp;gt; console.error(`Service Worker Error: ${err}`));
    });
} else {
    console.log("Service Worker is not supported by browser.");
}

&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here &lt;strong&gt;navigator&lt;/strong&gt; is an object which has methods and properties about the application running the script.&lt;/p&gt;

&lt;p&gt;The other steps are done within the &lt;strong&gt;sw.js&lt;/strong&gt; file. In order to do that, we will be adding several &lt;strong&gt;event listeners&lt;/strong&gt; to the window object.&lt;/p&gt;

&lt;p&gt;Suppose we have a very simple app with just 3 files &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;index.css&lt;/code&gt;, &lt;code&gt;script.js&lt;/code&gt;. Then we will need to add the following lines of code to the &lt;strong&gt;sw.js&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cacheName = "v1"; // Can be any string

const cachedAssets = ["index.html", "index.css", "script.js"];

// Call install event
self.addEventListener("install", (e) =&amp;gt; {
    e.waitUntil(
        caches
        .open(cacheName)
        .then((cache) =&amp;gt;
                cache.addAll(cachedAssets);
            })
        .then(() =&amp;gt; self.skipWaiting())
    );
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here you can see that we need to store the assets (files) that we need to store as cache, in an array and attach an &lt;strong&gt;install&lt;/strong&gt; event listener to the window object (self / this). Once the event is fired, a new cache folder is created by the name &lt;strong&gt;cacheName&lt;/strong&gt; &lt;code&gt;v1&lt;/code&gt; and the different assets are added to it.&lt;/p&gt;




&lt;p&gt;The next step of the process is to add an &lt;strong&gt;activate&lt;/strong&gt; event listener to the window object, and to check if the current cache &lt;code&gt;v1&lt;/code&gt; is the latest version available. To do so, copy the following code in the &lt;strong&gt;sw.js&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Call activate event

self.addEventListener("activate", (e) =&amp;gt; {
    // Remove unwanted cached assets
    e.waitUntil(
        caches.keys().then(cacheNames =&amp;gt; {
        return Promise.all(
            cacheNames.map(cache =&amp;gt; {
            if (cache !== cacheName) {
                return caches.delete(cache);
                }
            })
        );
        })
    );
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, we are accessing the various cached assets stored. In case you want to test it out yourself, try commenting out the above lines and changing the &lt;strong&gt;cacheName&lt;/strong&gt; to &lt;code&gt;v2&lt;/code&gt; , before saving the file. You will see that there are now 2 sets of cached assets, namely &lt;code&gt;v1&lt;/code&gt; and &lt;code&gt;v2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hEGlBhk5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AsuMhkzYAqU4Ujlm2CezlSw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hEGlBhk5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AsuMhkzYAqU4Ujlm2CezlSw.png" alt="Multiple instances of the same cached assets" width="535" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will end up consuming a lot more storage on the browser unless we delete the unwanted assets cached under a different &lt;strong&gt;cacheName&lt;/strong&gt;. This is where the &lt;strong&gt;activate&lt;/strong&gt; event listener comes in handy.&lt;/p&gt;

&lt;p&gt;Once the event is fired, all the &lt;strong&gt;keys&lt;/strong&gt; of the &lt;strong&gt;caches&lt;/strong&gt; object are obtained. These are nothing but the various cached assets under the name &lt;code&gt;v1&lt;/code&gt; , &lt;code&gt;v2&lt;/code&gt; and so on. These cacheNames are then compared with the current &lt;strong&gt;cacheName&lt;/strong&gt;, and if they do not match, that particular set of assets is deleted from the cache storage!&lt;/p&gt;




&lt;p&gt;Finally, the most vital step of the process is to &lt;strong&gt;fetch&lt;/strong&gt; &lt;strong&gt;assets from cache storage&lt;/strong&gt;. This is done by attaching a &lt;strong&gt;fetch&lt;/strong&gt; event listener to the window object, as shown below.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Call fetch event

self.addEventListener("fetch", (e) =&amp;gt; {
    e.respondWith(fetch(e.request)
                    .catch(() =&amp;gt; caches.match(e.request))
                    );
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The way that we have set up our service worker is pretty simple, hence the process of gathering cached assets, whenever a network request is made from the app is also pretty simple.&lt;/p&gt;

&lt;p&gt;All that we do in this step is wait until the &lt;strong&gt;fetch event&lt;/strong&gt; is fired, after this, we first try to access the required assets by making a network request. We perform the network request using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch"&gt;fetch() API&lt;/a&gt; (Do not confuse this with the event listener we have set up).&lt;/p&gt;

&lt;p&gt;But in case the app is offline, the fetch() API will not return the required data. This allows us to &lt;strong&gt;return the cached assets&lt;/strong&gt; as the response to the app’s original request. This will ensure that even though the app is offline, no error occurs when making a request for a cached asset!&lt;/p&gt;

&lt;p&gt;At the end of all 3 steps, your &lt;strong&gt;sw.js&lt;/strong&gt; file will be looking like this.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;






&lt;p&gt;This was just one method of creating a service worker, but if you want to cache &lt;strong&gt;every page&lt;/strong&gt; of your app, then modify your &lt;strong&gt;sw.js&lt;/strong&gt; file as follows.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You will notice that most of our work is now being done after the &lt;strong&gt;fetch&lt;/strong&gt; event is fired. This is because we are now adding every page we visit to the cache storage, by making a &lt;strong&gt;clone&lt;/strong&gt; of all the assets required to render that particular page.&lt;/p&gt;

&lt;p&gt;Although this seems like a pretty easy fix for caching the assets required for any app to function offline, this isn’t a one stop solution for all you caching needs! You will need to vary your service worker depending on the needs of your application.&lt;/p&gt;

&lt;p&gt;Lastly, in order to test if your app registers a valid service worker, you can take a look at the &lt;strong&gt;Service Workers&lt;/strong&gt; section under the &lt;strong&gt;Application&lt;/strong&gt; tab of the Chrome DevTools. To test if your app works offline, check the option that states &lt;strong&gt;offline&lt;/strong&gt; and refresh the page.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Are JavaScript Promises?</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 23 Aug 2020 18:36:54 +0000</pubDate>
      <link>https://dev.to/rajatm544/what-are-javascript-promises-4mp6</link>
      <guid>https://dev.to/rajatm544/what-are-javascript-promises-4mp6</guid>
      <description>&lt;p&gt;If you have never heard of Promises in JavaScript, chances are that you have experienced what is often termed as &lt;a href="http://callbackhell.com/"&gt;callback hell&lt;/a&gt;. &lt;strong&gt;Callback hell&lt;/strong&gt; is referring to the situation wherein you end up having nested callbacks to the extent that the readability of your code is severely hampered.&lt;/p&gt;

&lt;p&gt;If you have never experienced callback hell, let me give you a glimpse of what it looks like. Brace yourself and try to understand what the following piece of code is trying accomplish!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jcclKBQj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AGvjycZ-L72tVrY3byh_H1A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jcclKBQj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AGvjycZ-L72tVrY3byh_H1A.png" alt="An extreme example to illustrate callback hell" width="700" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, to be fair, &lt;em&gt;this might have been a slightly exaggerated example&lt;/em&gt;. But, it proves the point that attempting to nest callbacks can drastically reduce the readability of your code.&lt;/p&gt;

&lt;p&gt;In case you are wondering as to why you should bother about the readability of the code you write, then take a look at the following article which provides an in-depth answer to the query.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@egonelbre/psychology-of-code-readability-d23b1ff1258a" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dbkLIeeP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2AF6Wll9z_5dhUXEj9h4VHZA.png" alt="Egon Elbre"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@egonelbre/psychology-of-code-readability-d23b1ff1258a" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Psychology of Code Readability. By no means should this be regarded as… | by Egon Elbre | Medium&lt;/h2&gt;
      &lt;h3&gt;Egon Elbre ・ &lt;time&gt;Jul 21, 2018&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;Now that you realize that callback hell is notorious, let’s also briefly take a look at what causes a developer to fall into this trap in the first place.&lt;/p&gt;

&lt;p&gt;The main reason we use callbacks is to handle asynchronous tasks. Many a times, this can be because we need to make an API call, receive the response, convert it to JSON, use this data to make another API call and so on. This can seem like a problem that’s innate to JavaScript, because the nature of these API calls in asynchronous by default, and there seems to no workaround.&lt;/p&gt;

&lt;p&gt;This is where JavaScript Promises come into the picture, because it is a native JavaScript feature released as part of ES6, meant to be used to avoid callback hell, without having to break up the chain of API calls into different functions.&lt;/p&gt;




&lt;p&gt;A &lt;strong&gt;Promise&lt;/strong&gt; is an object that can be returned &lt;strong&gt;synchronously&lt;/strong&gt;, after the completion of a chain of asynchronous tasks. This object can be in one of the following 3 states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fulfilled&lt;/strong&gt;: This means that the asynchronous tasks did not throw any error, and that all of them have been completed successfully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rejected:&lt;/strong&gt; This means that one or more tasks has failed to execute as expected, and an error has been thrown.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pending:&lt;/strong&gt; This is like an intermediate state, wherein the Promise has neither been fulfilled nor been rejected.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We say that a Promise is &lt;strong&gt;settled&lt;/strong&gt;, if it is not in a pending state. This means that a Promise is settled even if it is in a rejected state.&lt;/p&gt;

&lt;p&gt;Promises can help us avoid callback hell, because they can be chained using &lt;strong&gt;.then()&lt;/strong&gt; any number of times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.then()&lt;/strong&gt; is non-blocking code. This means that the sequence of callback functions can run synchronously, as long the Promises are fulfilled at every stage of the asynchronous task.&lt;/p&gt;

&lt;p&gt;This way, no matter how many asynchronous tasks there need to be, all we need is a Promise based approach to deal with them!&lt;/p&gt;

&lt;p&gt;This can work because instead of immediately returning the final value, the asynchronous task returns a &lt;em&gt;Promise&lt;/em&gt; to supply the value at some point in the future. Since we have no code that blocks this operation, all the asynchronous tasks can take place as required, and the Promise that is returned will reflect whether or not they failed.&lt;/p&gt;




&lt;p&gt;By now, you understand what a Promise is. But how do you use them? Let’s deal with that in this section.&lt;/p&gt;

&lt;p&gt;Consider an example which uses plain old callbacks, which we can then convert to a Promise based approach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LYaRTLaU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A2Pa9UEox-5W01xNoMGNYGg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LYaRTLaU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A2Pa9UEox-5W01xNoMGNYGg.png" alt="An example for a set of callbacks" width="511" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, although this is a contrived example, it is pretty tricky to follow the chain of function calls as the number of callbacks increases. Now, if we chain all our callbacks to the returned promise itself, we can end up with the following Promise chain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--onxsCFaK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AKCtLP9L8-Zu7VTFaKJk2Xw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--onxsCFaK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AKCtLP9L8-Zu7VTFaKJk2Xw.png" alt="A Promise chain instead of nested callbacks" width="602" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we assume that the &lt;code&gt;demoFunction&lt;/code&gt; returns a Promise after it is invoked. This Promise eventually evaluates to either &lt;strong&gt;a valid result&lt;/strong&gt;, or &lt;strong&gt;an error&lt;/strong&gt;. In case the Promise is &lt;strong&gt;fulfilled&lt;/strong&gt;, the &lt;strong&gt;.then()&lt;/strong&gt; statement is executed.&lt;/p&gt;

&lt;p&gt;It is important to note that every .&lt;strong&gt;then()&lt;/strong&gt; returns a new Promise. So, when the &lt;code&gt;demoFunction&lt;/code&gt; returns a Promise, the resolved value is &lt;code&gt;result1&lt;/code&gt; which is used to invoke the next function in the chain, the &lt;code&gt;firstCallback()&lt;/code&gt;. This continues until the final callback is invoked.&lt;/p&gt;

&lt;p&gt;In case any of the Promises get &lt;strong&gt;rejected&lt;/strong&gt;, it means that an error was thrown by one of the callbacks. In that case, the remaining .then() statements are short-circuited and the &lt;strong&gt;.catch()&lt;/strong&gt; statement is executed.&lt;/p&gt;

&lt;p&gt;You may notice that a single &lt;strong&gt;.catch()&lt;/strong&gt; is needed to act as a error fallback, whereas in the previous version of the code, we had to provide &lt;code&gt;failureCallback&lt;/code&gt; function as a fallback error handler, to each callback function call.&lt;/p&gt;

&lt;p&gt;This way, you can easily convert a series of nested callbacks into a Promise chain.&lt;/p&gt;




&lt;p&gt;Until now we have learnt a new way to deal with callbacks using Promises. But we haven’t discussed where we get these Promises from. In this section, you can learn how to convert any function, such that it returns a Promise which can be chained to a list of &lt;strong&gt;.then()&lt;/strong&gt; statements.&lt;/p&gt;

&lt;p&gt;Consider the following example wherein we have a function which doesn’t return a Promise, hence it cannot be included in a Promise chain yet.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setTimeout(() =&amp;gt; callbackFunc("5 seconds passed"), 5\*1000);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, although the &lt;code&gt;callbackFunc&lt;/code&gt; has a very low chance of throwing an error, if it does do so, we have no way to &lt;strong&gt;catch&lt;/strong&gt; the error.&lt;/p&gt;

&lt;p&gt;In order to convert this function into one that returns a Promise, we can use the &lt;strong&gt;new&lt;/strong&gt; keyword as follow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const wait = ms =&amp;gt; new Promise((resolve, reject) =&amp;gt; {
        setTimeout(resolve, ms);
    };

    wait(5*1000)
        .then(() =&amp;gt; callbackFunc("5 seconds"))
        .catch(failureCallback);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, &lt;code&gt;wait&lt;/code&gt; represents a function which returns a &lt;strong&gt;new Promise&lt;/strong&gt; every time it’s invoked. We can do so using the Promise constructor, which creates a new Promise object. Hence, when &lt;code&gt;wait&lt;/code&gt; is invoked by passing a parameter indicating the duration for &lt;code&gt;setTimeout&lt;/code&gt; , it returns a Promise.&lt;/p&gt;

&lt;p&gt;Once the Promise reaches the &lt;strong&gt;fulfilled&lt;/strong&gt; state, the function associated with &lt;strong&gt;resolve&lt;/strong&gt; i.e, &lt;code&gt;callbackFunc&lt;/code&gt; is invoked. If the Promise is &lt;strong&gt;rejected&lt;/strong&gt;, then the &lt;code&gt;failCallback&lt;/code&gt; is executed.&lt;/p&gt;

&lt;p&gt;To further understand how to create your own Promises, you can go through &lt;a href="https://scotch.io/tutorials/javascript-promises-for-dummies#toc-creating-a-promise"&gt;this article&lt;/a&gt;, which provides a more complex example to do so.&lt;/p&gt;




&lt;p&gt;The best resource to dive deeper into the various instance methods in the &lt;strong&gt;Promise&lt;/strong&gt; constructor, is the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;MDN Docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Although the approach laid out in this article is a simple alternative to nested callbacks, a newer version of JavaScript (EcmaScript 2017 or ES8) also has a feature to deal with callback hell!&lt;/p&gt;

&lt;p&gt;In case you want to look into this feature called &lt;strong&gt;async &amp;amp; await&lt;/strong&gt;, you can go through the following article. Although it is stated as a brand new feature, it is actually just &lt;a href="https://stackoverflow.com/questions/50835572/what-is-syntactic-sugar-in-javascript"&gt;syntactic sugar&lt;/a&gt; over the concept of Promises discussed in this article! So, in case you understand the concept of Promises, the ES8 feature of async &amp;amp; await is pretty easy to comprehend.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@_bengarrison/javascript-es8-introducing-async-await-functions-7a471ec7de8a" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zhonCuSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2ANZJOMnfeXw7JE13o2pIxcA.jpeg" alt="Ben Garrison"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@_bengarrison/javascript-es8-introducing-async-await-functions-7a471ec7de8a" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Javascript — ES8 Introducing `async/await` Functions | by Ben Garrison | Medium&lt;/h2&gt;
      &lt;h3&gt;Ben Garrison ・ &lt;time&gt;Mar 22, 2018&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Hopefully, now that you are armed with Promises, you can successfully avoid falling prey to callback hell, the next time you are tasked with handling a bunch of callback functions!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>An Introduction to Flexbox in CSS.</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 16 Aug 2020 17:13:38 +0000</pubDate>
      <link>https://dev.to/rajatm544/an-introduction-to-flexbox-in-css-17i1</link>
      <guid>https://dev.to/rajatm544/an-introduction-to-flexbox-in-css-17i1</guid>
      <description>&lt;p&gt;CSS is the bane of many developers’ existence, as evidenced by &lt;a href="https://www.reddit.com/r/css/comments/3at81d/why_is_css_so_terrible/"&gt;this query&lt;/a&gt; on reddit.&lt;/p&gt;

&lt;p&gt;But CSS doesn’t really deserve the bad rap that it gets! Although everybody’s reasoning is different, the general consensus is that CSS is hard because it behaves weirdly. One such concept which scares off most beginners, is that of flexbox. But as you go through this article, it will become apparent to you that flexbox is actually a pretty easy concept to comprehend!&lt;/p&gt;

&lt;p&gt;Simply put, flexbox is tool to build layouts. It provides a cross browser-compatible method to implement layouts and makes it easier to add &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Responsive_Design"&gt;responsive design&lt;/a&gt; to your application, without you having to explicitly deal with positioning the components of your page.&lt;/p&gt;

&lt;p&gt;The only prerequisite to learn flexbox is &lt;strong&gt;CSS selectors&lt;/strong&gt;. In case you need to brush up on CSS selectors, you can go through the following article.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/front-end-weekly/understanding-css-selectors-1c03267e7cd2" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fojQsNvm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2A0EWbRGq2UypyhWZlWTNsJQ.jpeg" alt="Venky Royals"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/front-end-weekly/understanding-css-selectors-1c03267e7cd2" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Understanding CSS Selectors. So you want to learn CSS selectors? | by Venky Royals | Frontend Weekly | Medium&lt;/h2&gt;
      &lt;h3&gt;Venky Royals ・ &lt;time&gt;Feb 1, 2021&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;Just like the &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model"&gt;box model&lt;/a&gt; in CSS, there is something called the flex model, which can help you visualize the layout a lot better.&lt;/p&gt;

&lt;p&gt;The main principle of the flex model is that all its content is laid out along &lt;strong&gt;two axes&lt;/strong&gt;, namely a &lt;strong&gt;main axis&lt;/strong&gt; and a &lt;strong&gt;cross axis&lt;/strong&gt;. By default, the main axis refers to the x-axis or the &lt;strong&gt;horizontal axis&lt;/strong&gt;. Likewise, the cross axis refers to the y-axis or the &lt;strong&gt;vertical axis&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You might be aware that an outer container acts as &lt;strong&gt;parent element&lt;/strong&gt;, and all the elements nested within a container will act as &lt;strong&gt;child elements&lt;/strong&gt;. In the flex model, this parent element is called a &lt;strong&gt;flex container&lt;/strong&gt; and all its children are called &lt;strong&gt;flex items&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The following image gives a concise explanation of the flex model:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zmg3Ijmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AM_NAOezsj7UjvtSs5Nn3Pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zmg3Ijmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AM_NAOezsj7UjvtSs5Nn3Pg.png" alt="Illustration of flex model" width="563" height="333"&gt;&lt;/a&gt;&lt;em&gt;Illustration of flex model&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Consider the following HTML code, wherein we have a flex container and 4 flex items nested within it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---jxN-H0e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A03knBErjlCrorxfrRzkwtw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---jxN-H0e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A03knBErjlCrorxfrRzkwtw.png" alt="Example to illustrate flexbox" width="726" height="409"&gt;&lt;/a&gt;&lt;em&gt;Example to illustrate flexbox&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, if we select &lt;code&gt;flex-container&lt;/code&gt; and set its &lt;code&gt;display&lt;/code&gt; property to &lt;code&gt;flex&lt;/code&gt;, all the default flexbox properties are applied to it, as illustrated below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TSAIopbt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A5cNYjlYwAiDsyCjKhUXhig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TSAIopbt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A5cNYjlYwAiDsyCjKhUXhig.png" alt="Illustration to show default flex properties" width="733" height="442"&gt;&lt;/a&gt;&lt;em&gt;Illustration to show default flex properties&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s take a look at the different properties that are applied when an element’s &lt;code&gt;display&lt;/code&gt; property is set to be &lt;code&gt;flex&lt;/code&gt; .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;flex-direction&lt;/strong&gt;:This property sets the direction for the &lt;strong&gt;main axis&lt;/strong&gt; and by default, it is set as &lt;strong&gt;row&lt;/strong&gt;. The other options include &lt;strong&gt;reverse-row&lt;/strong&gt;, &lt;strong&gt;column&lt;/strong&gt;, and &lt;strong&gt;reverse-column.&lt;/strong&gt; The following image shows the difference between these four values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iNMohQlo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A6ugjQc3_4nnS94f8IJqoVw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iNMohQlo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A6ugjQc3_4nnS94f8IJqoVw.png" alt="Illustration to show flex-direction" width="800" height="451"&gt;&lt;/a&gt;&lt;em&gt;Illustration to show flex-direction&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;flex-wrap&lt;/strong&gt;: Wrapping refers to the process of distributing the flex items over multiple lines. This property is set to &lt;strong&gt;nowrap&lt;/strong&gt; by default, as flexbox will try to position all the flex items onto the &lt;strong&gt;main axis&lt;/strong&gt;. The options available under this property are &lt;strong&gt;wrap&lt;/strong&gt;, &lt;strong&gt;wrap-reverse&lt;/strong&gt;, and &lt;strong&gt;nowrap&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;flex-flow:&lt;/strong&gt; This is a shorthand property to set the previous 2 properties at once. The order of the properties is flex-flow: flex-direction flex-wrap . The default value is &lt;strong&gt;row nowrap&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Up until now, all the properties I listed were used to either set the direction of the main axis, or to allow flex items to be distributed over multiple lines. The following properties are responsible for the &lt;strong&gt;alignment&lt;/strong&gt; of the flex items within the flex container.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;justify-content:&lt;/strong&gt; This property sets the alignment along the &lt;strong&gt;main axis&lt;/strong&gt;. By default, its value is set to &lt;strong&gt;flex-start&lt;/strong&gt;. But there are many more options which will help in the construction of the desired layout, as listed below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vblQNsbf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2ATIEKszRwPLu6QrFC_HvDBQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vblQNsbf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2ATIEKszRwPLu6QrFC_HvDBQ.png" alt="Illustration to explain the different options for justify-content" width="506" height="521"&gt;&lt;/a&gt;&lt;em&gt;Illustration to explain the different options for justify-content&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;align-items:&lt;/strong&gt; This property is used to align the flex items along the &lt;strong&gt;cross axis&lt;/strong&gt;. By default, this property is set to &lt;strong&gt;stretch&lt;/strong&gt;, which indicates that the flex items will fill the container (along the cross axis, of course). Like the ‘justify-content’ property, this too has other options to align the flex items, as illustrated below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nvhtiQ-o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2ArRfSj0cG98cyWjExPL_KFw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nvhtiQ-o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2ArRfSj0cG98cyWjExPL_KFw.png" alt="Illustration to explain the different options for align-items" width="506" height="533"&gt;&lt;/a&gt;&lt;em&gt;Illustration to explain the different options for align-items&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;align-content:&lt;/strong&gt; This is used to align the flex-container’s lines within the container, only when there is extra space in the cross-axis. This is similar to justify-content, but it works on an entire line of flex-items, rather than individual items. The following image illustrates the options available in align-content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QNdu0otf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AzggWhuDL9EBLfgYcolgnIw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QNdu0otf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AzggWhuDL9EBLfgYcolgnIw.png" alt="Illustration to explain different options for align-content" width="513" height="534"&gt;&lt;/a&gt;&lt;em&gt;Illustration to explain different options for align-content&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note that &lt;strong&gt;align-content&lt;/strong&gt; will have no effect on your layout in case your main axis has a single line of flex items.&lt;/p&gt;




&lt;p&gt;Now, let us take a look at the properties that can be applied to the &lt;strong&gt;flex items&lt;/strong&gt;, which are nested within the flex container.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The ‘&lt;strong&gt;order&lt;/strong&gt;’ property is used to override the default order of the flex items. The default is the order in which they appear in the HTML source. Its value can be set using an integer as seen in the image below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--608Jee5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AMIlRe0KDAl5E33IuRSGC4A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--608Jee5k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AMIlRe0KDAl5E33IuRSGC4A.png" alt="The flex-items’ order can be seen within the orange boxes" width="680" height="382"&gt;&lt;/a&gt;&lt;em&gt;The flex-items’ order can be seen within the orange boxes&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The &lt;strong&gt;align-self&lt;/strong&gt; property is used to set the alignment of individual flex items, along the &lt;strong&gt;cross axis&lt;/strong&gt;. This property will override the alignment set by the ‘align-items’ property.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3HFACmUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A-wOglEOPyqPH25UAyrzvSQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3HFACmUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A-wOglEOPyqPH25UAyrzvSQ.png" alt="An example to illustrate align-self" width="366" height="205"&gt;&lt;/a&gt;&lt;em&gt;An example to illustrate align-self&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The options that are available in this property are the same as those of &lt;strong&gt;align-items&lt;/strong&gt; and the default is set as auto .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Lastly, there is property called &lt;strong&gt;flex&lt;/strong&gt;, which is a shorthand responsible for setting the &lt;strong&gt;flex-grow, flex-shrink&lt;/strong&gt; and &lt;strong&gt;flex-basis&lt;/strong&gt; properties. You can find a detailed explanation of this sub-property &lt;a href="https://css-tricks.com/almanac/properties/f/flex/#:~:text=The%20flex%20property%20is%20a,flex%2Dbasis%20%29%20are%20optional."&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Now that you know the basics of flexbox, the next hurdle to overcome is to be able to construct layouts using flexbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tobiasahlin.com/blog/common-flexbox-patterns/"&gt;This resource&lt;/a&gt; provides examples of some common layouts found in most modern websites.&lt;/p&gt;

&lt;p&gt;But, in case you want to be able to build your very own layout, the best method to practise is by converting a PSD template into a CSS file. This means replicating PSD templates using just CSS flexbox! Doing this will help you instantly spot common design patterns which can be achieved using flexbox, which will in turn strengthen your flexbox skills!&lt;/p&gt;

&lt;p&gt;A popular resource for Photoshop templates is &lt;a href="https://dribbble.com/"&gt;dribbble&lt;/a&gt;. You can start by taking a look at &lt;a href="https://dribbble.com/tags/website_psd_template"&gt;this list of template designs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you are able to build layouts resembling the above templates, you have already overcome your dread for CSS!&lt;/p&gt;

&lt;p&gt;Two very useful resources for diving deeper into other CSS concepts include the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS"&gt;MDN docs&lt;/a&gt;, and the &lt;a href="https://css-tricks.com/"&gt;css-tricks&lt;/a&gt; website.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>flexbox</category>
    </item>
    <item>
      <title>What Are Higher Order Array Methods in JavaScript?</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 09 Aug 2020 17:10:54 +0000</pubDate>
      <link>https://dev.to/rajatm544/what-are-higher-order-array-methods-in-javascript-f8d</link>
      <guid>https://dev.to/rajatm544/what-are-higher-order-array-methods-in-javascript-f8d</guid>
      <description>&lt;p&gt;If you’ve been programming for &lt;strong&gt;any&lt;/strong&gt; amount of time, you would be familiar with arrays. They are the among the first data structures taught in most programming lectures/courses. For good reason too, because they are pretty easy to work with. But in case you work in JavaScript, using arrays can be made a whole lot simpler with the help of some useful higher order methods!&lt;/p&gt;

&lt;p&gt;The reason that these are called &lt;strong&gt;Higher Order Methods&lt;/strong&gt; is that they can accept/return another function. If this seems a tad bit confusing, then it’s important that you understand why &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/First-class_Function#:~:text=A%20programming%20language%20is%20said,a%20value%20to%20a%20variable."&gt;&lt;strong&gt;functions are first class citizens&lt;/strong&gt;&lt;/a&gt; in JavaScript. It is just a fancy way of saying that functions are just like any other type of data, which can be stored, accessed, passed as arguments and even returned from another method!&lt;/p&gt;

&lt;p&gt;The following image does a pretty good job at describing what a higher order function is&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pplOEwyP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AjCvQfxJQHXstWN7vE2tVww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pplOEwyP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AjCvQfxJQHXstWN7vE2tVww.png" alt="Credit: @joelnet on twitter"&gt;&lt;/a&gt;&lt;em&gt;Credit: &lt;a class="comment-mentioned-user" href="https://dev.to/joelnet"&gt;@joelnet&lt;/a&gt;
 on twitter&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;A quick heads up. These higher order methods will require the usage of callbacks and they will be a lot easier to write, if you are familiar with the &lt;strong&gt;arrow syntax&lt;/strong&gt; of &lt;strong&gt;ES6&lt;/strong&gt;. In case you’re not, you can go through the following section to see what it is. Here’s a pretty basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// normal function definition
function add(a, b) {
  return (a + b)
}

// arrow syntax
const add = (a, b) =&amp;gt; (a + b);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You can convert a normal function definition into its arrow syntax counterpart, using the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Remove the &lt;code&gt;function&lt;/code&gt; keyword and replace it with either &lt;code&gt;const&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt; . We can do this because functions are &lt;em&gt;first-class objects in JavaScript&lt;/em&gt;. (&lt;strong&gt;Note:&lt;/strong&gt; In case you want an &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions"&gt;anonymous function&lt;/a&gt;, just remove the &lt;code&gt;function&lt;/code&gt; keyword and move to step 2)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, put an arrow symbol &lt;code&gt;=&amp;gt;&lt;/code&gt; in front of the arguments’ list, to indicate that the code following it will be the body of the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After this, you can type curly braces and write the function body as usual. But, if your function body has just 1 line (the return statement), you can skip the curly braces, skip the return keyword, and just type out the expression that needs to be returned!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For functions with no argument, just leave empty brackets before the &lt;code&gt;=&amp;gt;&lt;/code&gt; symbol.&lt;br&gt;
&lt;code&gt;const alertMsg = () =&amp;gt; alert("This is just an example!")&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lastly, if you are handling just 1 argument in the function, you can skip the parenthesis around it.&lt;br&gt;
&lt;code&gt;const squared = x =&amp;gt; (x \*\* 2)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Now that you have brushed up on the arrow syntax, let’s begin to understand some higher order array methods!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;forEach()&lt;/strong&gt;: Think of it as a less verbose implementation of a &lt;code&gt;for loop&lt;/code&gt;. It invokes a function on &lt;strong&gt;each&lt;/strong&gt; array element, and its syntax goes like this:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.forEach((element, index) =&amp;gt; {
    // some operations on the element
    // maybe you want to use the index of the element
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In case you want to see a pretty contrived example, take a look at the following example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZY0psgzH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A6EfY0yi-rp2UhFYOor-c6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZY0psgzH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A6EfY0yi-rp2UhFYOor-c6g.png" alt="Example for forEach()"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;map()&lt;/strong&gt; : If you’ve understood forEach(), then this is a piece of cake! It functions exactly like a forEach, but &lt;strong&gt;returns a new array&lt;/strong&gt; unlike the forEach() method. The syntax is as follows:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const returnedArr = array.map((currentEle) =&amp;gt; {
    // some operation on currentEle
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It’s slightly different to the forEach() method, but you should be able to use them interchangeably for most applications. In case you want to know about the differences, you can go through &lt;a href="https://www.freecodecamp.org/news/4-main-differences-between-foreach-and-map/#:~:text=forEach%28%29%20does%20not%20mutate%20the%20array%20on%20which%20it%20is%20called.&amp;amp;text=The%20map%28%29%20method%20returns,original%20array%20with%20the%20callback%20."&gt;this article&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;reduce()&lt;/strong&gt; is especially useful whenever you need to compute a single value based on the data stored in an array. As the name suggests, this reduces an array into a single value, but can be a little tricky to use! The callback function that this method accepts, works on each element of the array in a way that reduces the array to a single value. The syntax is as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const reducedVal = array.reduce(callback, initialVal);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, &lt;code&gt;callback&lt;/code&gt; needs to take &lt;strong&gt;2 arguments&lt;/strong&gt;. The first argument acts as an &lt;strong&gt;accumulator&lt;/strong&gt;, whose value persists throughout the process. The second represents the &lt;strong&gt;current value&lt;/strong&gt; of the array.&lt;/p&gt;

&lt;p&gt;A simple example can be to find the sum of the array elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DQ_o2b4c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A3Q5uRxWDs6WqLG7z7EEcbw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DQ_o2b4c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A3Q5uRxWDs6WqLG7z7EEcbw.png" alt="Example for reduce()"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, the &lt;code&gt;reduce()&lt;/code&gt; method has a callback function called &lt;code&gt;reducerCallback&lt;/code&gt; (very creative, I know!). This callback needs to have 2 arguments, I called mine &lt;code&gt;acc&lt;/code&gt; and &lt;code&gt;current&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;The basic idea is that the value in &lt;code&gt;acc&lt;/code&gt; is &lt;strong&gt;persisted&lt;/strong&gt; each time the callback method is executed. This means that if the &lt;code&gt;reducerCallback&lt;/code&gt; is executed for the 2nd element of demo , then the values of the arguments &lt;code&gt;acc&lt;/code&gt; and &lt;code&gt;current&lt;/code&gt; are, &lt;strong&gt;12&lt;/strong&gt; and &lt;strong&gt;34&lt;/strong&gt; respectively. The callback then adds these two values and returns them. This returned value is now the new value stored in &lt;code&gt;acc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So, for the 3rd callback execution, the values of &lt;code&gt;acc&lt;/code&gt; and &lt;code&gt;current&lt;/code&gt; are &lt;strong&gt;46&lt;/strong&gt; and &lt;strong&gt;54&lt;/strong&gt;. You can see how the array’s values are being used to get to a single value.&lt;/p&gt;

&lt;p&gt;But I also mentioned a second argument called &lt;code&gt;initialVal&lt;/code&gt; in the syntax. This is set as the initial value of the &lt;code&gt;acc&lt;/code&gt; variable. In case you do not specify any &lt;code&gt;initialVal&lt;/code&gt; argument, &lt;code&gt;acc&lt;/code&gt; will take the array element at the &lt;strong&gt;0th index&lt;/strong&gt; as its &lt;strong&gt;default initial value&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is an article that gives you a verbose explanation about the workings of the &lt;code&gt;reduce()&lt;/code&gt; method&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/javascript-in-plain-english/4-practices-to-help-you-understand-array-reduce-f3138cfef095" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q1Gp0QKm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/2%2AaVrH2Vy2EAhAXBTpnGSbVA.png" alt="bitfish"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/javascript-in-plain-english/4-practices-to-help-you-understand-array-reduce-f3138cfef095" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;4 Practices to Help You Understand array.reduce() | by bitfish | JavaScript In Plain English | Medium&lt;/h2&gt;
      &lt;h3&gt;bitfish ・ &lt;time&gt;Feb 18, 2020&lt;/time&gt; ・ 6 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;The next method that is used often is &lt;strong&gt;filter()&lt;/strong&gt;. It is very helpful if you want to extract a sub-array from a larger array, based on some common property. The syntax is as follows&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const filteredArr = array.filter(callback);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here &lt;code&gt;callback&lt;/code&gt; accepts an argument &lt;code&gt;current&lt;/code&gt; which results is a &lt;strong&gt;boolean value being returned&lt;/strong&gt;. Based on the return value, the &lt;code&gt;current&lt;/code&gt; value is &lt;strong&gt;pushed&lt;/strong&gt; to &lt;code&gt;filteredArr&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, suppose you want to separate the even numbers from a given array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L9zA9u0c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AtsmUpHe6n0N0z8i_yS2SgA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L9zA9u0c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AtsmUpHe6n0N0z8i_yS2SgA.png" alt="Example to filter out even numbers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, the &lt;code&gt;callback&lt;/code&gt; function is anonymous and it accepts an argument that represents the current element of the &lt;code&gt;demo&lt;/code&gt; array. If the &lt;code&gt;callback&lt;/code&gt; returns &lt;strong&gt;&lt;code&gt;true&lt;/code&gt;&lt;/strong&gt; then &lt;code&gt;item&lt;/code&gt; is &lt;strong&gt;pushed&lt;/strong&gt; to the resultant array &lt;code&gt;filteredArr&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here, for all the even numbers in &lt;code&gt;demo&lt;/code&gt; , our &lt;code&gt;callback&lt;/code&gt; returns a &lt;strong&gt;0(zero)&lt;/strong&gt;, which is &lt;strong&gt;falsy&lt;/strong&gt; in nature. Hence, all the even numbers are omitted from &lt;code&gt;filteredArr&lt;/code&gt; . On the other hand, all the odd numbers return &lt;strong&gt;1(one)&lt;/strong&gt; which is equivalent to true . This way, our &lt;code&gt;demo&lt;/code&gt; array has been filtered!&lt;/p&gt;

&lt;p&gt;You can go through the following article to see some more examples.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://codeburst.io/learn-understand-javascripts-filter-function-bde87bce206" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_N_wHhXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/0%2AqH2Wle1736qoCJj3." alt="Brandon Morelli"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://codeburst.io/learn-understand-javascripts-filter-function-bde87bce206" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Learn &amp;amp; Understand JavaScript’s Filter Function | by Brandon Morelli | codeburst&lt;/h2&gt;
      &lt;h3&gt;Brandon Morelli ・ &lt;time&gt;Nov 19, 2017&lt;/time&gt; ・ 4 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        codeburst.io
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;Lastly, let’s understand a higher order method used most often. &lt;strong&gt;sort()&lt;/strong&gt; is a method that doesn’t quite work like we assume it would!&lt;/p&gt;

&lt;p&gt;You would imagine that the following code works by sorting the array in ascending order by default, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const demo = [100, 20, 89, 3, 17];
demo.sort();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But, it returns the array &lt;code&gt;[100, 17, 20, 3, 89]&lt;/code&gt; . “What? Why?”, I hear you say. Let’s understand why &lt;strong&gt;sort()&lt;/strong&gt; has such a behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;sort()&lt;/strong&gt; assumes that all the array elements are &lt;code&gt;String&lt;/code&gt; by default, and sorts the elements based on the UTF-16 code values, in case it is not passed any callback!&lt;/p&gt;

&lt;p&gt;This is why 100 will come before 20. In order to sort an array in a more traditional way (i.e, as numbers) we will need to use a callback function as follows &lt;code&gt;array.sort(callback)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;callback&lt;/code&gt; needs to accept &lt;strong&gt;2 arguments&lt;/strong&gt; and return a numeric value indicating how these 2 arguments need to be stored in the &lt;em&gt;sorted array.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is an example to sort an array of elements in ascending order:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--89dDc7LE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AioM69QBxs5bKFAiwntFHQQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--89dDc7LE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AioM69QBxs5bKFAiwntFHQQ.png" alt="Example to sort array in ascending order"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If &lt;code&gt;callback(a, b)&lt;/code&gt; returns less than 0, &lt;code&gt;a&lt;/code&gt; comes before &lt;code&gt;b&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If &lt;code&gt;callback(a, b)&lt;/code&gt; returns 0, &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are left at their current index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If &lt;code&gt;callback(a, b)&lt;/code&gt; returns greater than 0, &lt;code&gt;b&lt;/code&gt; comes before &lt;code&gt;a&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that &lt;code&gt;callback(a, b)&lt;/code&gt; must always return the same value when given a specific pair of elements &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; as its two arguments.&lt;/p&gt;

&lt;p&gt;Here &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are the 2 consecutive elements of the &lt;code&gt;demo&lt;/code&gt; array, which are continuously compared in the &lt;code&gt;callback&lt;/code&gt;. Here, if you wanted to sort the array in descending order, all you need to do is change the &lt;code&gt;callback&lt;/code&gt; to the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y03vnjlg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AsOMfKibDvOub_g1mL0d9ag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y03vnjlg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AsOMfKibDvOub_g1mL0d9ag.png" alt="Example to sort an array in descending order"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you want to look at more examples of how to use the &lt;strong&gt;sort()&lt;/strong&gt; method, you can go through the following article.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/madhash/demystifying-the-mysteries-of-sort-in-javascript-515ea5b48c7d" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0G3xTlaX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AAp0cL-mIXt1wVV-Iti6Bdg.jpeg" alt="Aphinya Dechalert"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/madhash/demystifying-the-mysteries-of-sort-in-javascript-515ea5b48c7d" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Demystifying the Mysteries of sort() in JavaScript | by Aphinya Dechalert | Mad Hash*Map* | Medium&lt;/h2&gt;
      &lt;h3&gt;Aphinya Dechalert ・ &lt;time&gt;Mar 2, 2020&lt;/time&gt; ・ 5 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;All said and done, these methods are a sliver of all the higher-order array methods offered by JavaScript. Although these are the methods that you’ll use on a more regular basis, it is not a futile attempt to go through the rest of the methods!&lt;/p&gt;

&lt;p&gt;In case you wish to learn more about any of these array methods, or if you want to learn some more higher order methods, I’d suggest that you go to the &lt;a href="https://developer.mozilla.org/en-US/"&gt;MDN Docs&lt;/a&gt;, as it provides a pretty thorough explanation of all the methods that JavaScript has to offer.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>es6</category>
      <category>arrays</category>
    </item>
    <item>
      <title>A Guide to Learn React.js</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 02 Aug 2020 16:38:13 +0000</pubDate>
      <link>https://dev.to/rajatm544/a-guide-to-learn-react-js-3ko5</link>
      <guid>https://dev.to/rajatm544/a-guide-to-learn-react-js-3ko5</guid>
      <description>&lt;p&gt;There is a ton of options when it comes to client side frameworks, and often it can be a little confusing for beginners to choose from the wide range of choices. Often these choices boil down to Angular, React and Vue. &lt;em&gt;“So, which is the best choice?”&lt;/em&gt;, you may ask. I can’t help but give you the clichéd answer that there isn’t really a &lt;strong&gt;best choice&lt;/strong&gt;. Just pick one and learn it &lt;strong&gt;thoroughly&lt;/strong&gt;, would be the best advice to give, because all the three choices eventually boil down to very similar working strategies.&lt;/p&gt;

&lt;p&gt;In case you have made up your mind to start learning React, I shall do my best to give you a thorough introduction of the same!&lt;/p&gt;




&lt;p&gt;One of the reasons why React can seem &lt;em&gt;weird&lt;/em&gt; to a beginner is that there isn’t a separation of concerns in terms of writing HTML and writing React code. This can seem awkward for most beginners, because when building any application’s client-side, we usually use a template engine like EJS, Handlebars, Mustache, and so on. So the shift to a client-side library which &lt;strong&gt;merges&lt;/strong&gt; the use of HTML and JavaScript can be a little tough!&lt;/p&gt;

&lt;p&gt;The very first concept to start with React is called &lt;strong&gt;JSX&lt;/strong&gt;, which stands for JavaScript XML. Basically, JSX allows us to write HTML within React itself. Although there are a &lt;em&gt;few&lt;/em&gt; changes, in order to write JSX (which is what every React component eventually renders) you just need to know the basic tags of HTML!&lt;/p&gt;

&lt;p&gt;You can go through the &lt;a href="https://reactjs.org/docs/jsx-in-depth.html"&gt;&lt;strong&gt;this article&lt;/strong&gt;&lt;/a&gt; from the official docs, in order to familiarize yourself with the concept of converting the HTML tags into JSX code for React to render.&lt;/p&gt;




&lt;p&gt;Now that we understand how to write JSX, let’s try to understand how React can help us build the User Interface (UI) of an application.&lt;/p&gt;

&lt;p&gt;React (&lt;em&gt;and most other client-side frameworks)&lt;/em&gt; primarily work by rendering &lt;strong&gt;components&lt;/strong&gt;. This enables a developer to build one component, and re-use it multiple times as required. This is a powerful advantage over using a template engine, because you no longer have to worry about writing code to build all parts of the UI! To illustrate this, consider the example of Youtube’s homepage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lmE8oldi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3840/1%2AX3cNBqadW9fJ9x440GLWfQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lmE8oldi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3840/1%2AX3cNBqadW9fJ9x440GLWfQ.png" alt="Notice the repeated use of a similar component" width="800" height="450"&gt;&lt;/a&gt;&lt;em&gt;Notice the repeated use of a similar component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here, notice how all the video suggestion cards have a similar structure to them. &lt;em&gt;A thumbnail&lt;/em&gt;, a &lt;em&gt;title&lt;/em&gt; below the thumbnail, &lt;em&gt;the channel name&lt;/em&gt; below that, and &lt;em&gt;some&lt;/em&gt; &lt;em&gt;more details&lt;/em&gt; towards the bottom of the card. Using a client side library like React, you can build a generic component to display all of the above, and re-use that same component multiple times.&lt;/p&gt;

&lt;p&gt;To leverage this concept, it is important to start thinking of the UI as a structured collection of components. These components can also communicate with one another &lt;strong&gt;asynchronously&lt;/strong&gt;, which can save you some costly page reloads!&lt;/p&gt;

&lt;p&gt;“But, how do I build these components?”, you may wonder. Building components mainly comes down to understanding what you want to render for the user, at that instant of time. If you can visualize the end result before you start writing the code, it can make your job a little easier.&lt;/p&gt;

&lt;p&gt;React offers two ways to define the components. You can either choose to build a &lt;strong&gt;class-based component&lt;/strong&gt;, or you can build a &lt;strong&gt;functional component&lt;/strong&gt;. As the names suggest, the former uses the concept of &lt;em&gt;ES6 Javascript classes&lt;/em&gt; (if you are not familiar with it, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes"&gt;&lt;strong&gt;click here&lt;/strong&gt;&lt;/a&gt; to learn about it) and the latter uses plain-old &lt;em&gt;Javascript&lt;/em&gt; &lt;em&gt;functions&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In case you aren’t able to decide which type of component you should learn first, I would suggest that you learn about functional components, because it is a little more forgiving towards folks with a lesser knowledge of JavaScript classes. You can go through the &lt;a href="https://www.freecodecamp.org/news/how-to-write-your-first-react-js-component-d728d759cabc/"&gt;&lt;strong&gt;this article&lt;/strong&gt;&lt;/a&gt; to write your very first component, be it class-based or function-based.&lt;/p&gt;




&lt;p&gt;Now that you are aware of the concept of components, the next important aspect to understand is that of the &lt;strong&gt;state of a component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;state&lt;/strong&gt; of any component refers to all the data that a component needs to store, in order for it to work as expected. In simpler terms, think of the state as a reservoir of data that every component holds. In case the state of a component changes, React will automatically trigger the component to be re-rendered with the updated state!&lt;/p&gt;

&lt;p&gt;There are two ways to set the state of the component, depending on the type of component you choose to build. Although you can just stick to using one type of component for every app, I would suggest that you go through both approaches, as it helps you better judge as to which component is more suited for the current application.&lt;/p&gt;

&lt;p&gt;Use the following two articles to set the state for a class-based component and a functional component, respectively.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/get-pro-with-react-setstate-in-10-minutes-d38251d1c781/"&gt;&lt;strong&gt;How to become a pro with React setState() in 10 minutes&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.logrocket.com/a-guide-to-usestate-in-react-ecb9952e406c/"&gt;&lt;strong&gt;A guide to useState() in React&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s take a look at what all we have learnt until now, shall we? We learnt that React renders components. We learnt that the entire UI can be built using various components. We also learnt that the components can have their own &lt;strong&gt;state&lt;/strong&gt;. But how will all our components talk to one another? We will need some mechanism to let the components transfer data to each other, right?&lt;/p&gt;




&lt;p&gt;This is where we come across another important feature of React, called &lt;strong&gt;props&lt;/strong&gt;. If you have worked with HTML, this concept is very easy to comprehend. Look at the following tag, wherein we use an &lt;strong&gt;attribute&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;img src="some/image.png" alt="sample image" &amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here we are setting &lt;strong&gt;properties&lt;/strong&gt; of the tag, by specifying attributes such as src(source) and alt(alternate text). Similarly, in order to send some data from one component to another, we set them as &lt;strong&gt;properties(props)&lt;/strong&gt; of the component being rendered (the child component).&lt;/p&gt;

&lt;p&gt;Another simple analogy to understand props is that of &lt;strong&gt;function arguments&lt;/strong&gt;. They are essential for the proper working of the function, but not all functions need them. Similarly, we can have components(of any type) with and without props.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3qUXPRMn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2ADLgChSa4jfNXDAMcM9_JEg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3qUXPRMn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2ADLgChSa4jfNXDAMcM9_JEg.jpeg" alt="Illustration to understand state and props" width="675" height="423"&gt;&lt;/a&gt;&lt;em&gt;Illustration to understand state and props&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The above image illustrates how React Components are able to use the concepts of &lt;strong&gt;state&lt;/strong&gt; and &lt;strong&gt;props&lt;/strong&gt;. An important detail to understand here is that a component can alter its state, but its props are immutable(read-only). This just means that a parent component is responsible for setting the props of its child component, and the child component cannot change them.&lt;/p&gt;

&lt;p&gt;Having said all this, there are can always be a case wherein a component neither needs a state nor props! So don’t assume that every component that you build in React needs to have a state, or that it needs props. You can go through the &lt;a href="https://blog.logrocket.com/the-beginners-guide-to-mastering-react-props-3f6f01fd7099/"&gt;&lt;strong&gt;this article&lt;/strong&gt;&lt;/a&gt; for a more robust introduction to the concept of props.&lt;/p&gt;




&lt;p&gt;All the concepts I have listed up until now form the basics of React, but there’s much more to it!&lt;/p&gt;

&lt;p&gt;The concepts of React are best understood only after you actually try them out yourself. In order to do that, open the CLI of your choice and navigate to the folder you want to start writing React code in. After you do so, type the following shell command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app &amp;lt;your-app-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note that you will need to have installed &lt;strong&gt;Node.js&lt;/strong&gt; and &lt;strong&gt;npm&lt;/strong&gt; in your local machine, in order to execute this shell command. If not, then &lt;a href="https://nodejs.org/en/download/"&gt;&lt;strong&gt;go here&lt;/strong&gt;&lt;/a&gt; and download Node. You can check if the installation was complete, by typing the shell command &lt;code&gt;node -v&lt;/code&gt; or &lt;code&gt;npm -v&lt;/code&gt; which should return a valid version number.&lt;/p&gt;

&lt;p&gt;Here, executing &lt;code&gt;npx &amp;lt;command&amp;gt; when &amp;lt;command&amp;gt;&lt;/code&gt; isn’t already in your &lt;code&gt;$PATH&lt;/code&gt; will automatically install a package with that name from the &lt;strong&gt;npm registry&lt;/strong&gt; for you, and invoke it. In short, it lets you execute a command without having to explicitly download a pre-requisite file/tool for your local machine.&lt;/p&gt;

&lt;p&gt;Also, note that your ‘app-name’ must be in lower case and can be seperated by a hyphen. So you can just name a folder as your app-name and run the following shell command &lt;code&gt;npx create-react-app .&lt;/code&gt; which creates an app of the same name as your current folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1PBlKVG9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2072/1%2AXVz7Mflg3H4owM8K_VWwJA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1PBlKVG9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2072/1%2AXVz7Mflg3H4owM8K_VWwJA.png" alt="Command to create a new React app of the same name as the current folder" width="800" height="225"&gt;&lt;/a&gt;&lt;em&gt;Command to create a new React app of the same name as the current folder&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This command can take a while to finish downloading all the files. Once it finishes downloading all the files, you can open the folder in a code-editor of you choice, and see a list of files similar to the ones in the below image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4YSpRRMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A9IiCW6uFeZtZOHHZ85K9aA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4YSpRRMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A9IiCW6uFeZtZOHHZ85K9aA.png" alt="Files downloaded from create-react-app" width="183" height="462"&gt;&lt;/a&gt;&lt;em&gt;Files downloaded from create-react-app&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can type &lt;code&gt;npm start&lt;/code&gt; to test that your react app is up and running! You can follow the steps in the next section to clean up the folder and start writing React code.&lt;/p&gt;




&lt;p&gt;In case you want to clean up the folders that &lt;code&gt;create-react-app&lt;/code&gt; downloads, you can start by typing the shell command &lt;code&gt;rm -rf .git&lt;/code&gt; in the CLI to remove the git repo that &lt;code&gt;create-react-app&lt;/code&gt; creates for you. After this, you can start with your own git workflow. Check out this article to learn how to setup a basic git workflow, in case you do not know how to do so.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/rajatm544" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5W8-gGje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.dev.to/cdn-cgi/image/width%3D150%2Cheight%3D150%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto/https%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Fuser%252Fprofile_image%252F354169%252Fafab7ff9-70ff-4b29-b4bd-1287aefc9db0.jpg" alt="rajatm544"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/rajatm544/a-simple-introduction-to-git-46a" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;A Simple Introduction to Git.&lt;/h2&gt;
      &lt;h3&gt;Rajat M ・ Jul 26 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#git&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;After you do so, you can choose to delete all the files in the public directory, &lt;strong&gt;except&lt;/strong&gt; the files &lt;strong&gt;index.html&lt;/strong&gt; and &lt;strong&gt;manifest.json&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the src directory, you can go ahead and delete the files App.test.js , index.css , logo.svg . Unless you want to set up tests for your app, or you plan on converting this app into a &lt;a href="https://web.dev/what-are-pwas/"&gt;&lt;strong&gt;PWA&lt;/strong&gt;&lt;/a&gt;, you can also go ahead and delete the files serviceWorker.js and setupTests.js .&lt;/p&gt;

&lt;p&gt;Now you have a bare-bones folder with the basic requirements to start working with React. But you can also cleanup your index.html file by deleting the unwanted comments. Note that in case you chose to delete the serviceWorker.js file, make sure that you comment out the following lines from your index.js file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wssBbObL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Ao0EOJ14FPxavk_fDKAbmHQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wssBbObL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Ao0EOJ14FPxavk_fDKAbmHQ.png" alt="Comment out the service worker registration line" width="800" height="87"&gt;&lt;/a&gt;&lt;em&gt;Comment out the service worker registration line&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Also make sure to adjust the imports in the files that are left in your folder, to remove the lines that are trying to import the deleted files!&lt;/p&gt;

&lt;p&gt;But, in case you feel overwhelmed by these changes, you can choose not to fiddle with any of these files (i.e, not delete them) and to perform all your changes in the App.js file!&lt;/p&gt;




&lt;p&gt;One last feature to understand before you can go ahead and learn the more advanced topics in React, is that of the parent-child relation between the various components. For example, when you bootstrap your React app using &lt;code&gt;create-react-app&lt;/code&gt; then only the component from the index.js file is being rendered by React. The index.js file is further invoking the App.js component! This is very important to realize early on, because at the end of the day, any application you build using React, will be a single page application. But that doesn’t mean that you can only render one parent component!&lt;/p&gt;

&lt;p&gt;In case all this seems a little confusing, go through the &lt;a href="https://flaviocopes.com/single-page-application/"&gt;&lt;strong&gt;this article&lt;/strong&gt;&lt;/a&gt; to understand the meaning of a single page application.&lt;/p&gt;




&lt;p&gt;Lastly, if you feel like a video tutorial with a more hands-on approach to learning will help you learn the basics of React a little better, then do check out this &lt;a href="https://scrimba.com/g/glearnreact"&gt;&lt;strong&gt;free course&lt;/strong&gt;&lt;/a&gt;. But do note that it &lt;em&gt;does not&lt;/em&gt; include the latest concepts of React hooks (i.e, the use of functional components)&lt;/p&gt;

&lt;p&gt;Once you feel comfortable with the basic concepts of React, you can go ahead and learn about &lt;a href="https://css-tricks.com/learning-react-router/"&gt;&lt;strong&gt;React Router&lt;/strong&gt;&lt;/a&gt; to integrate it with you current server-side tech stack and build full stack applications. Or you can learn the more &lt;a href="https://reactresources.com/topics/advanced-concepts"&gt;&lt;strong&gt;advanced topics in React&lt;/strong&gt;&lt;/a&gt;. You can also check out the following article to help you gauge the topics you might need to use!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/wineofbits/concepts-to-become-an-advanced-react-developer-684d90c086c2" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BLS-jFI4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fill:88:88/1%2AvNIuIff72ATOhg1uFgeUcQ.jpeg" alt="Dhanraj Acharya"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/wineofbits/concepts-to-become-an-advanced-react-developer-684d90c086c2" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Concepts to become an advanced React developer | by Dhanraj Acharya | wineofbits | Medium&lt;/h2&gt;
      &lt;h3&gt;Dhanraj Acharya ・ &lt;time&gt;Nov 16, 2018&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YjpYcCMa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Simple Introduction to Git.</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Sun, 26 Jul 2020 16:19:09 +0000</pubDate>
      <link>https://dev.to/rajatm544/a-simple-introduction-to-git-46a</link>
      <guid>https://dev.to/rajatm544/a-simple-introduction-to-git-46a</guid>
      <description>&lt;p&gt;It’s a common misconception that Git is only meant to be used by &lt;em&gt;programmers&lt;/em&gt;, but the truth is that it is a versatile tool that can be utilized by people from all walks of life. In this post I shall give you an insight as to why Git is essential, why it can be confusing, and most importantly, as to how you can leverage it.&lt;/p&gt;

&lt;p&gt;But before we begin using Git, let us understand why we might need to use it in the first place. Sure, it as an essential tool in a developer’s toolkit, but the reasoning behind the usage of Git has to be more than just that it’s a popular tool, right?&lt;/p&gt;

&lt;p&gt;An analogy that helped me understand the &lt;em&gt;need for Git&lt;/em&gt; was that of &lt;strong&gt;snapshots&lt;/strong&gt;. Imagine that you have started building a personal project. It is something that you have wanted to build since a long time. Eventually you notice that there is more than one way to implement a feature in your project. So you choose one of these ways and trudge along. A week into the development process, you realize that certain decisions in the project’s past are hampering some new features. So you just go back to the problematic section of the project and fix it! A few more days pass by, and your project is nearing its completion. Alas, you run into some more design bugs! This time you notice that there isn’t a simple fix, because this bug is a culmination of a series of flaws in the project.&lt;/p&gt;

&lt;p&gt;You start contemplating your options. Do you go back and re-design every problematic aspect of the project, meanwhile risking some unnoticed side-effects? Do you ask for help online? Do you scrap the project? Can you just &lt;em&gt;ctrl+z&lt;/em&gt; your way to the point where you wrote the buggy line?&lt;/p&gt;

&lt;p&gt;This can seem like a contrived example, but it is a scenario that &lt;em&gt;every&lt;/em&gt; developer has faced at some point! In fact, Linus Torvalds has even said that he created Git just to maintain the &lt;em&gt;slightly bigger&lt;/em&gt; project he happened to be working on.&lt;/p&gt;

&lt;p&gt;This is where you realize the importance of a &lt;strong&gt;version control software&lt;/strong&gt; like Git. As the name suggests, it is something that helps you keep track of the different versions of your project. This is where the analogy of snapshots comes in. Using Git is like maintaining an album filled with snapshots of your work. It makes it easier to pinpoint bugs, because it has a recorded history of &lt;em&gt;all the work&lt;/em&gt; that you put in while building the project.&lt;/p&gt;

&lt;p&gt;Git has features which also helps a team of people &lt;strong&gt;collaborate&lt;/strong&gt;. If you want to imagine a scenario wherein Git can actually save your life, then revisit the example I gave a little while ago. But instead of &lt;em&gt;you&lt;/em&gt; being the only one who is stuck with buggy code, &lt;em&gt;it is an entire team of 10/100/1000&lt;/em&gt; with all of them working on different parts of the project! Calling this situation a nightmare would be an understatement!&lt;/p&gt;




&lt;p&gt;Now that we know Git can save us from mental breakdowns, let’s get started with the workflow involved!&lt;/p&gt;

&lt;p&gt;The acronym to remember is &lt;strong&gt;ISAC.&lt;/strong&gt; Let me explain.&lt;/p&gt;

&lt;p&gt;In order to get started it’s important that you have a working knowledge of a command line interpreter or a &lt;strong&gt;CLI&lt;/strong&gt;. If not, then read the following paragraph to get started with a CLI of your choice. In case you have never used a CLI before, it is just an interface for you to give some commands/instructions to your computer.&lt;/p&gt;

&lt;p&gt;On a MAC machine, search for the program named &lt;strong&gt;Terminal&lt;/strong&gt;.&lt;br&gt;
On an Ubuntu machine, press Ctrl+Alt+T.&lt;br&gt;
Once you open the Terminal, you will need to install git &lt;a href="https://git-scm.com/downloads"&gt;from here&lt;/a&gt;.&lt;br&gt;
On a Windows machine, I would suggest that you &lt;a href="https://git-scm.com/downloads"&gt;go here&lt;/a&gt; and download a CLI called the &lt;strong&gt;git bash.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Verify the git installation by typing &lt;code&gt;git --version&lt;/code&gt; in your CLI. It should return a number indicating the version of git.&lt;/p&gt;




&lt;p&gt;Once you have opened a CLI, navigate to the folder where you want to save your project files, using the &lt;strong&gt;cd&lt;/strong&gt; command as required. Once you are in the root (main) directory of your project (which is yet to be started), you can start with the git workflow using the acronym I mentioned earlier.&lt;/p&gt;

&lt;p&gt;In order to allow Git to store snapshots of your code, you need to create &lt;strong&gt;an empty, local repository&lt;/strong&gt;. Think of it like creating an empty backup folder. You do this by typing git init . You should see the text &lt;strong&gt;(master)&lt;/strong&gt; alongside your file pathname, once you execute this command.&lt;/p&gt;

&lt;p&gt;If you type ls -a you should see a file called &lt;strong&gt;.git&lt;/strong&gt;, which will now act as you local repo — short for repository.&lt;/p&gt;

&lt;p&gt;Now, you can go ahead and create all the files that you need to build your project. Note that the development procedure you follow to build a project is unaffected by the addition of Git to the picture. Once you have created some files in the folder that the git repo was initialized in, go ahead and type git status in your CLI.&lt;/p&gt;

&lt;p&gt;You should see statements similar to the one below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lj573Rc4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2078/1%2AUvSusgQsfXph4kZ-teC-nw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lj573Rc4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2078/1%2AUvSusgQsfXph4kZ-teC-nw.png" alt="Example for message returned after typing ‘git status’" width="800" height="235"&gt;&lt;/a&gt;&lt;em&gt;Example for message returned after typing ‘git status’&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This message indicates that there are &lt;strong&gt;untracked files&lt;/strong&gt; in our git repository. This just means that the files are not ready to be added to our local git repository yet. In order to continue with our git workflow, we will need to use another git command.&lt;/p&gt;

&lt;p&gt;This is where things can get a little tricky to understand, because Git doesn’t directly store our files in a local repository. Instead, it allows the user to &lt;strong&gt;add&lt;/strong&gt; these files to a &lt;strong&gt;staging area&lt;/strong&gt;. “Why?” , you may ask. It is because we might have some local files, that we do not want to store in the local git repository, another reason might be to allow us to split our commits into logical sections rather than it being a block of unrelated changes. If you found this difficult to understand, then refer the first answer to this query on stackoverflow.&lt;/p&gt;


&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AoTUKOcU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/49228209/whats-the-use-of-the-staging-area-in-git" rel="noopener noreferrer"&gt;
            What's the use of the staging area in Git?
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Mar 12 '18&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 6&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/49228209/whats-the-use-of-the-staging-area-in-git" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oeieW07A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          80
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h2-sXgSn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;What is the point of &lt;code&gt;git add .&lt;/code&gt; or &lt;code&gt;git add &amp;lt;filename&amp;gt;&lt;/code&gt; to add it to the staging area? Why not just  &lt;code&gt;git commit -m "blabla"&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;I don't understand the value of the staging area.&lt;/p&gt;

    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/49228209/whats-the-use-of-the-staging-area-in-git" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;In short, when you see that you have untracked files, you need to type the following command to &lt;strong&gt;add&lt;/strong&gt; those files to the staging area&lt;br&gt;
&lt;code&gt;git add &amp;lt;path/filename&amp;gt;&lt;/code&gt; or if you want to add all the files at once, type &lt;code&gt;git add .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you type git status again, you will see a different message!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--feV0v2CI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2080/1%2AwX7aGhlQO6iIkzfWC1ziVA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--feV0v2CI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2080/1%2AwX7aGhlQO6iIkzfWC1ziVA.png" alt="git status after adding our files to the staging area" width="800" height="222"&gt;&lt;/a&gt;&lt;em&gt;git status after adding our files to the staging area&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note that if you make changes to any of your files, &lt;strong&gt;after you add&lt;/strong&gt; them to the staging area, then it will have to be added again, because the &lt;em&gt;version&lt;/em&gt; of the file in the staging area is no longer the same file in our local environment.&lt;/p&gt;

&lt;p&gt;The next step is to transfer the files from the &lt;strong&gt;staging area&lt;/strong&gt; to the &lt;strong&gt;local repository&lt;/strong&gt;. In order to do that, type the following command&lt;br&gt;
&lt;code&gt;git commit &amp;lt;path/filename&amp;gt; -m "a message regarding this commit"&lt;/code&gt;&lt;br&gt;
This is where we meet a new Git feature called &lt;strong&gt;Commit Messages&lt;/strong&gt;(Note the &lt;strong&gt;-m&lt;/strong&gt;). They are succinct messages which convey information regarding the files that are being committed.&lt;/p&gt;

&lt;p&gt;To understand the importance of these messages, imagine that a year has passed since the time you have finished a project. You decide to go back to it and see the code for the project. Or, more realistically, suppose a team member has to get familiarized with your codebase. In these cases, in order to make sense of &lt;em&gt;why&lt;/em&gt; certain changes were made in the files, you will rely on these &lt;strong&gt;commit messages&lt;/strong&gt;, because you no longer have the context for the code you had written.&lt;/p&gt;

&lt;p&gt;If you want to commit all the files in the staging area at once, then type the following command&lt;br&gt;
&lt;code&gt;git commit -m "&amp;lt;commit message&amp;gt;"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since commit messages are so crucial for code maintenance, here are some tips for writing good commit messages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Type it in present tense, for example &lt;code&gt;Make foo do something&lt;/code&gt; , rather than in past tense like &lt;code&gt;Made foo do something&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Be concise. &lt;code&gt;Add style to the form&lt;/code&gt; is better than &lt;code&gt;Add style to make the form look better and also added a new background color to the submit button&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This is what the most basic Git workflow looks like. It’s that simple! Just remember the following commands: &lt;strong&gt;I&lt;/strong&gt;nit, &lt;strong&gt;S&lt;/strong&gt;tatus, &lt;strong&gt;A&lt;/strong&gt;dd, &lt;strong&gt;C&lt;/strong&gt;ommit.&lt;br&gt;
In order to have a rough overview of the various aspects in Git, see the following image&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---62WBJju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AlWS_YsYDgGNzwleoSK8jOg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---62WBJju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AlWS_YsYDgGNzwleoSK8jOg.png" alt="Basics of git" width="738" height="605"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The workflow that I have mentioned up until now, is the most basic workflow one can follow in order to use Git. But when Git is to be used for collaboration purposes, it is often the case then we need to &lt;strong&gt;merge&lt;/strong&gt; branches, send/accept &lt;strong&gt;pull requests&lt;/strong&gt;, &lt;strong&gt;fetch&lt;/strong&gt; files from another Git repo, &lt;strong&gt;checkout&lt;/strong&gt; a previous version of the project, &lt;strong&gt;push&lt;/strong&gt; our files to a remote repo provided by Github(alternatives include Gitlab, Bitbucket), &lt;strong&gt;pull&lt;/strong&gt; files from the remote repo, &lt;strong&gt;clone&lt;/strong&gt; another user’s remote repo, and so on. But since all these commands are easier to grasp once you have an understanding about the basics of Git, I shall provide resources for you to learn these topics once you feel like you have grasped what Git does.&lt;/p&gt;

&lt;p&gt;These are some of the best resources I found:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/gothamv" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4PpuBsxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.dev.to/cdn-cgi/image/width%3D150%2Cheight%3D150%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto/https%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Fuser%252Fprofile_image%252F194803%252F8ed39a44-6e4a-450d-9ad2-3b3d94bdc039.png" alt="gothamv"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/gothamv/learn-the-basics-of-git-in-under-10-minutes-475c" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Learn the Basics of Git in Under 10 Minutes&lt;/h2&gt;
      &lt;h3&gt;Gowtham Venkatesan ・ Jul 13 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#github&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#git&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="/unseenwizzard" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6hHUwh6K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.dev.to/cdn-cgi/image/width%3D150%2Cheight%3D150%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto/https%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Fuser%252Fprofile_image%252F174788%252Fc6a77d88-7bf4-41c0-8a97-fac421d88ae9.png" alt="unseenwizzard"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/unseenwizzard/learn-git-concepts-not-commands-4gjc" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Learn git concepts, not commands&lt;/h2&gt;
      &lt;h3&gt;Nico Riedmann ・ Jun 2 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#git&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#learning&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;If you feel like a video tutorial would help you better understand these concepts then checkout &lt;a href="https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZF9C0YMKuns9sLDzK6zoiV"&gt;this playlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, another reason to start using Git is that you can contribute to open source. One of the main reasons why Git is as popular as it is, is the fact that it has allowed &lt;em&gt;hundreds and thousands&lt;/em&gt; of developers to collaborate. Hence it is not too much of a stretch to claim that &lt;em&gt;Git is the foundation for all Open Source Software.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Beginner Friendly Guide to the World of Web Wevelopment.</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Mon, 20 Jul 2020 05:07:51 +0000</pubDate>
      <link>https://dev.to/rajatm544/a-beginner-friendly-guide-to-the-world-of-web-development-4kh6</link>
      <guid>https://dev.to/rajatm544/a-beginner-friendly-guide-to-the-world-of-web-development-4kh6</guid>
      <description>&lt;p&gt;This article is going to be helpful only if &lt;strong&gt;you&lt;/strong&gt; identify yourself as a beginner, and trust me when I say that there shouldn’t be any shame in doing so.&lt;br&gt;
If you are someone who has toyed with the idea of getting into web development or if you’re someone who knows how to code, but doesn’t know what to do with it, then I shall try and show you the things that can help you in the journey that you’re about to set out on.&lt;/p&gt;

&lt;p&gt;First off, let’s get familiar with a few terms. These are jargon that you’ll see in &lt;em&gt;every&lt;/em&gt; article about web development.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Web development&lt;/strong&gt;: It encompasses a lot of technologies that are used to build &lt;em&gt;dynamic&lt;/em&gt; applications. To be fair, this term can include a host of other things, but for the purposes of this article assume that every application that you see online, is built using this process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Front-End&lt;/strong&gt;: It is the section of the app that a user interacts with, it can also be called as the &lt;em&gt;client-side&lt;/em&gt; of any application. It can further include concepts like UI, UX, Layout, Responsive design, and so on. But don’t get intimidated by the previous line, and assume the &lt;em&gt;front-end&lt;/em&gt; to be the part of an app that an end-user interacts with, in their browser window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Back-End&lt;/strong&gt;: It is the section of the app that is abstracted from the user. Think of it as the stuff that lies behind the front-end, providing the functionality intended for the app that you are building. It’s often also called the &lt;em&gt;server-side&lt;/em&gt; of the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Full-Stack&lt;/strong&gt;: You’ve guessed it! It’s a seamless combination of the &lt;em&gt;front-end&lt;/em&gt; and the &lt;em&gt;back-end&lt;/em&gt;. This is why web development can also be called any of the following terms and still mean the same thing: &lt;em&gt;Full-stack development&lt;/em&gt;, &lt;em&gt;Full-stack engineering&lt;/em&gt;, &lt;em&gt;Software development&lt;/em&gt;, and so on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Framework and Library&lt;/strong&gt;: Although they technically do differ, it is a fair assumption to think of them as &lt;em&gt;tools that provide an abstraction over a more complex task, but with their own set of rules that need to be followed in order to use them effectively.&lt;/em&gt;&lt;br&gt;
In simpler terms, they allow us to complete complex tasks with lesser code. I would suggest that while using frameworks to accomplish a task, that you also see the &lt;em&gt;raw&lt;/em&gt; version of the code, in order to develop an appreciation for the level of abstraction that a framework provides.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API&lt;/strong&gt;: It is the interface which allows the &lt;em&gt;client-side&lt;/em&gt; and the &lt;em&gt;server-side&lt;/em&gt; to &lt;em&gt;talk&lt;/em&gt; to one another. It’s usually the boundary between various software. So every time you use a full stack app, you are likely interacting with an API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Database&lt;/strong&gt;: It just stores data for our application. Majorly of two types, SQL and NoSQL. The difference between the two is very easy to comprehend, so a quick google search should do you justice!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Now that you are familiar with some jargon, let’s also take a brief overview of how a web-based application is able to work. This is something that’s usually irrelevant after you start building the application, but I believe it to be an essential concept to comprehend the general workflow involved in the development process. The following image represents an &lt;em&gt;over-simplified&lt;/em&gt; web request-response cycle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SIc9Yuye--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/700/1%2A9x3R2-sc5d1hcyshT-BvdQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SIc9Yuye--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/700/1%2A9x3R2-sc5d1hcyshT-BvdQ.png" alt="Web request-response cycle" width="700" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If this image helped you better understand the jargon I mentioned earlier, then that meets the purpose of me including this concept!&lt;/p&gt;



&lt;p&gt;If you’ve ever researched as to what are the tools required for you to become a web developer, it is likely that you would have come across &lt;em&gt;hundreds of them&lt;/em&gt;! &lt;strong&gt;You do not have to know every tool there is!&lt;/strong&gt; This is a trap that most of us fall into, especially early on in the process of learning. I could rattle out names of at least 50 tools which are used in the development process, but that doesn’t mean that your skill set needs to reflect that.&lt;/p&gt;

&lt;p&gt;Here is the part of the article where I shall suggest that you learn &lt;em&gt;so-and-so&lt;/em&gt; tech stack to become a web developer &lt;strong&gt;in a week!&lt;/strong&gt; That’s right! Learn &lt;em&gt;this&lt;/em&gt; to get a job &lt;strong&gt;within a week!&lt;/strong&gt; That ought to have caught your attention, after all I am going to reveal the &lt;strong&gt;secret to become a software developer!&lt;/strong&gt; or &lt;strong&gt;a web developer!&lt;/strong&gt; whatever you want to call yourself.&lt;br&gt;
But the harsh truth is that &lt;em&gt;there isn’t one&lt;/em&gt;. In fact, one of the reasons why there isn’t a one-stop solution for learning web development, is the fact that there are so many tools!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8pq75jddacotjr8g3h4y.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8pq75jddacotjr8g3h4y.jpg" alt="Collage of some tools off the top of my head" width="610" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The point of this image is not to scare anybody off, &lt;em&gt;but to illustrate some of the job requirements posted online!&lt;/em&gt;&lt;br&gt;
Jokes aside, the most common starting point to learn web development would be the standard trio of &lt;strong&gt;HTML&lt;/strong&gt;, &lt;strong&gt;CSS&lt;/strong&gt; and &lt;strong&gt;JavaScript&lt;/strong&gt;. A brief understanding of these 3 tools can be found below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;: It provides the basic skeleton for the web page and is used to build the &lt;strong&gt;structure&lt;/strong&gt; of the app. It is also instrumental is deciding as to what are the elements that need to be displayed. It is the only language that a browser can covert into a web page. The learning curve for HTML is not too steep, because it doesn’t really include any &lt;em&gt;programming logic&lt;/em&gt; per se.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CSS&lt;/strong&gt;: It is responsible for &lt;strong&gt;styling&lt;/strong&gt; the structure built by HTML. This means that CSS can be used to beautify the bare bones structure built using HTML, by applying a host of properties. The learning curve for CSS can be a little steep, but trust me when I say that you would much rather spend the time to learn CSS at an earlier stage, than struggle with it after the fact! A free resource to learn it can be found &lt;a href="https://css-tricks.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;: This is responsible for adding the &lt;strong&gt;functionality&lt;/strong&gt; to the &lt;em&gt;beautified structure&lt;/em&gt; built using the previous two tools. This is probably the first &lt;em&gt;programming language&lt;/em&gt; in the list, and is a truly vast topic. So you shouldn’t try and learn it within a few days, but instead spend a significant chunk of time on it. Build loads of mini projects to understand the basics of DOM, event handlers, promises and the other quirks of the language. If you need any more motivation to learn JavaScript, then please &lt;a href="https://image.slidesharecdn.com/becomeawebdeveloperakaicampbeginner1-140402034322-phpapp01/95/become-a-webdeveloper-akaicamp-beginner-1-19-638.jpg?cb=1396410717"&gt;click here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An analogy that helped me grasp the importance of these tools, is that of a humanoid robot. Think of the physical body(structure) of the robot to be made using HTML. Think of the outer appearance(style) to be built using CSS. Finally, think of the actual brain/processor of the robot to built using JavaScript. &lt;em&gt;I know that it’s a contrived example&lt;/em&gt;, but it is one that can make it easier to understand the importance of each of the above tools.&lt;/p&gt;



&lt;p&gt;Up until now, we’ve been discussing about the tools to build the client-side of the application. So let’s dive into the server-side of things!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is where it’s totally up to you to decide what you want to use.&lt;/em&gt; All I can do is list the various options available to build the back-end of your application. Another common jargon used to describe our server-side is API. So don’t get confused when you see the words &lt;strong&gt;API endpoints&lt;/strong&gt; in some of the tutorials. It just refers to the points of contact between the front-end and the back-end, in order to get/post data.&lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;what does our back-end do?&lt;/strong&gt; It is responsible for retrieving, storing, processing and refining data, so that some useful information can be sent to the client-side, if need be. In order to store the data, the server-side of an application often uses a &lt;em&gt;database&lt;/em&gt; of some kind.&lt;/p&gt;

&lt;p&gt;The various languages that can be used to build the back-end are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Python:&lt;/strong&gt; The frameworks offered in this language are Flask and Django.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js:&lt;/strong&gt; Yes, you can just use the same language throughout the development process. Some frameworks offered in this language are Express, Koa and Strapi.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GoLang:&lt;/strong&gt; A very easy language to start off with!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PHP:&lt;/strong&gt; This is not really the preferred choice nowadays, but is one of the options available. Laravel is a pretty popular PHP framework that’s still around.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I would certainly be remiss if didn’t include at least one of the various client-side frameworks.&lt;br&gt;
But I strongly suggest complete beginners to not bother learning a client-side frameworks, until they are comfortable in building the client-side of their applications using vanilla JavaScript (&lt;em&gt;No, that’s not a rib at the vanilla enthusiasts of the world&lt;/em&gt;). Of course, you would still need to use HTML and CSS for the structure and the styling respectively.&lt;br&gt;
This advise can seem naive at first, especially since most developers always seem to be ready to jump into the &lt;em&gt;Angular vs React vs Vue&lt;/em&gt; battle, but I say this because it allows us to properly differentiate the perks offered by the framework, from those offered by vanilla JavaScript itself.&lt;/p&gt;



&lt;p&gt;Finally in order to deploy your application you can use one of the following tools: Heroku, Netlify, Github-pages. Here &lt;strong&gt;deploying&lt;/strong&gt; is the process of taking the app from &lt;em&gt;working-on-your-local-machine&lt;/em&gt; to &lt;em&gt;working-online&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;Another important aspect of the workflow involved in the development process is that of a &lt;em&gt;version control system&lt;/em&gt;. Think of it as snapshots of your code at different times, which you can refer back to, at any point in the future. It is also helpful in maintaining the codebase. &lt;strong&gt;Git&lt;/strong&gt; is the most often used &lt;em&gt;version-control-system&lt;/em&gt;, and it is a very easy tool to learn. Once you feel comfortable working with Git, you can also put up the code for the application you built, on &lt;strong&gt;Github&lt;/strong&gt; (&lt;em&gt;in a remote repository&lt;/em&gt;) for easier collaboration.This will also officially make you an &lt;strong&gt;Open Source Contributor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s basically it! I’ve given you a rough overview of all the steps involved in the development process. I have deliberately refrained myself from suggesting a specific set of tools because &lt;em&gt;tutorial purgatory&lt;/em&gt; is a concept that is better averted than coped with. Check out this article I posted a while back, to understand what I mean by this.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/rajatm544" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5W8-gGje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.dev.to/cdn-cgi/image/width%3D150%2Cheight%3D150%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto/https%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Fuser%252Fprofile_image%252F354169%252Fafab7ff9-70ff-4b29-b4bd-1287aefc9db0.jpg" alt="rajatm544"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/rajatm544/only-you-can-learn-web-development-3cp9" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Only you can learn web development!&lt;/h2&gt;
      &lt;h3&gt;Rajat M ・ Apr 14 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Finally, there is a skill that’s probably the most important. But I leave it up to you to find out more about it! May be you can &lt;strong&gt;google it&lt;/strong&gt;, or maybe you can find out more about it on &lt;strong&gt;stackoverflow&lt;/strong&gt; (&lt;em&gt;wink, wink&lt;/em&gt;).&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Personalize Your Web Wpp with a Favicon, Completely Free of Cost!</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Mon, 06 Jul 2020 07:04:41 +0000</pubDate>
      <link>https://dev.to/rajatm544/personalize-your-web-app-with-a-favicon-completely-free-of-cost-1082</link>
      <guid>https://dev.to/rajatm544/personalize-your-web-app-with-a-favicon-completely-free-of-cost-1082</guid>
      <description>&lt;p&gt;It has recently been a complete revelation to me that being a good developer is only half the battle won, if you want your project to stand out from the rest. What matters at the end of your endeavor to build a few personal projects to add to your ever-growing portfolio, is that the project must be presentable. By this I mean that your work should seem polished, and the most basic of things, can actually go a long way in terms of elevating the project you build.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;favicons&lt;/strong&gt; come into the picture. They are essentially the logo that represents your project in a browser’s address bar, or the logo that a user sees when the app is installed on a device (assuming that it’s a Progressive Web Application i.e, a PWA). In this piece, I will list a set of resources that can help you feel the same ecstasy that I felt, when I accidentally stumbled upon the fact that a simple icon can actually improve the presentability of your web application.&lt;/p&gt;

&lt;p&gt;Before we begin, it is of paramount importance that the icon that you choose, actually represents what your project is about. This may sound trivial, but it is something that needs to be kept at the back of one’s mind when choosing from a vast list of icon options, because if the icon you choose doesn’t end up as an honest representation of your work, then the favicon shall serve very little purpose.&lt;/p&gt;

&lt;p&gt;Okay, let’s dive in!&lt;/p&gt;

&lt;p&gt;First of all, head over to &lt;a href="https://favicon.io/"&gt;favicon.io&lt;/a&gt; and see what type of an icon will suit your project the most. This can include an &lt;strong&gt;existing emoji&lt;/strong&gt;, as an example let’s assume that you’re building a really simple weather application, in this case it makes sense to have either &lt;em&gt;the Sun&lt;/em&gt;, or &lt;em&gt;the clouds&lt;/em&gt; as the favicon, so it’s easy to choose the respective emoji and call it quits, as it makes the entire process ever so simple. If not an emoticon, then maybe you want a simple &lt;strong&gt;text-based icon&lt;/strong&gt;, like that of &lt;em&gt;Medium&lt;/em&gt; or &lt;em&gt;dev.to&lt;/em&gt;, because it’s relatively simple to customize a text-based icon when compared to an image-based icon. If you are content with either of these cases, then just follow the steps in the next section, and your work’s done!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffmrobwkvw370arsw6au9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffmrobwkvw370arsw6au9.png" alt="Choose any of the highlighted options to create the icon from text or emoji" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you choose an emoji or finish adding the text, download the various files generated and follow these instructions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Place those files in the root of your project, which is usually the public directory or the folder which contains your &lt;em&gt;index.html&lt;/em&gt; file (i.e. in the main html file of your application)&lt;/li&gt;
&lt;li&gt;Add the following link tags to the &lt;strong&gt;head&lt;/strong&gt; of your &lt;em&gt;index.html&lt;/em&gt; file, which allows the browser set a new favicon for your project.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"&amp;gt;&lt;br&gt;
&amp;lt;link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"&amp;gt;&lt;br&gt;
&amp;lt;link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"&amp;gt;&lt;br&gt;
&amp;lt;link rel="manifest" href="/site.webmanifest"&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Once you do this, your job’s done! It’s that simple. Reload the window, and see the browser tab indicate the icon you just added.&lt;/p&gt;

&lt;p&gt;Personally, I would recommend that you go ahead and choose the third option (&lt;em&gt;technically speaking, the first option&lt;/em&gt;) of converting a .png file to an icon. But fret not, I will present a complementary free resource that makes this task quite simple. Just in case you choose to create your own icon using a tool like Adobe XD, you can do so, but make sure to export it as a png file. In this case, you can just skip the next part, and upload your file to favicon.io, and after you download the files that are generated, just follow the steps mentioned in the previous section.&lt;/p&gt;

&lt;p&gt;But you can skip designing the icon yourself, and just choose from an already existing library of icons from &lt;a href="https://www.flaticon.com/"&gt;flaticon.com&lt;/a&gt; and even customize an icon you like, to better represent the colour palette of your project! Make sure to attribute the designer once you download your icon, since they have basically done all the hard work for you. &lt;strong&gt;Be sure to download your icon in the .png format&lt;/strong&gt;, for it to be compatible with favicon.io&lt;/p&gt;

&lt;p&gt;Repeat the process I mentioned earlier, to convert the file into a favicon, and if you feel like the icon needs some tweaking, just repeat the entire process within a couple of minutes, until the icon is just the way you want it to be!&lt;/p&gt;

&lt;p&gt;For example, below is the icon I chose to add as the favicon for a &lt;a href="https://mern-blog-it.herokuapp.com/"&gt;blogging application&lt;/a&gt; that I built. It’s clearly not the most eye-catching, but just about gets the idea of the app across.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbm95yzmqhae9me4ctiob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbm95yzmqhae9me4ctiob.png" alt="Example icon" width="192" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, these are not the only tools that you can use in order to set up your very own favicon, there are other free resources out there, that do provide very similar functionalities, and you will eventually stumble upon them! So if there’s one takeaway from this post, let it be the fact that there are many ways to get to the same outcome, and it’s only a matter of personal preference, so try finding innovative solutions to any problem at hand, and keep sharing your findings!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>favicon</category>
    </item>
    <item>
      <title>Only you can learn web development!</title>
      <dc:creator>Rajat M</dc:creator>
      <pubDate>Tue, 14 Apr 2020 08:20:10 +0000</pubDate>
      <link>https://dev.to/rajatm544/only-you-can-learn-web-development-3cp9</link>
      <guid>https://dev.to/rajatm544/only-you-can-learn-web-development-3cp9</guid>
      <description>&lt;p&gt;This post is for anybody looking to finally take up web development. Be it as a hobby that you hope to turn into a career, or to just code, because you love to code but don't really know what to do with it. But it is relevant to anybody who is a developer.&lt;/p&gt;

&lt;p&gt;So you start searching for ways to learn this new thing that has peaked your interest, but you quickly realize that there are virtually thousands upon thousands of video lectures, Udemy courses, Coursera courses, edX courses, well you get the point, and you are lost within the tremendous pile of content that you've decided to throw yourself into. So you may choose to back off a little and see what google suggests you learn first. But once you start doing that, you're rapidly slipping into the rabbit hole that is the endless stream of requirements that google searches tell you to acquire before you can call yourself a &lt;strong&gt;web developer&lt;strong&gt;.&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So after a couple of hours, you turn to the good old trusty Youtube suggestions to see if there's a comprehensible video from a fairly popular source that can help you navigate these confusing waters that you find yourself in, and to be fair there is a ton of videos freely available on Youtube, that can concisely tell you what you need to do, but the problem here is that you don't really know which advice to follow.&lt;/p&gt;

&lt;p&gt;So after a day's worth of research you've decided that you'll follow a tutorial you found on Youtube to build your first dynamic web application, using either Flask or Django or Node.js or Ruby on rails, and I digress. But at this point of time you have no clue what any of these jargon mean, so you just follow along with the tutorial of choice and manage to build the exact same app as the instructor, albeit on your local environment. You are thrilled! You feel a sense of achievement! You feel like you've done the most important part of the process of learning web dev, you've built something!&lt;/p&gt;

&lt;p&gt;But, then, you see this video pop up in the suggestions that is also claiming to be beginner friendly, it also has a good number of views on it, and it has positive comments about it helping people learn easily. So onward you go, you click it, follow that tutorial for the next couple of days, and once again, you've done it! You have managed to replicate the app in the tutorial. The obvious question to ask would be &lt;b&gt;"What next?"&lt;/b&gt;, right? Well, at this point of time you are starting to realize that going on a hunt for videos to learn from, is a bit of a challenge, so it ought to be better if you complete a course on one of the many sites that offer them.&lt;/p&gt;

&lt;p&gt;So you find yourself going through that tutorial for the next couple of months (or weeks, or days, it can vary) and at the end of it, &lt;b&gt;you've become a web developer!&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;If only it were as easy as that! The point of this post is not to tell you to follow a specific course, or a tutorial series, there are numerous other such posts already available. The point of this post is to warn you about something that's often called tutorial hell or tutorial purgatory, and that just means that you feel like your skills are available to you only when you are following a tutorial, and that you are not a good enough developer when you try and build something &lt;b&gt;on your own&lt;/b&gt;. The reason this comes up is because usually all our paths of becoming a web developer are different, but they always depend on the same sources of information. &lt;/p&gt;

&lt;p&gt;So, what about that title? It just means that no matter how you learn full stack development, at the end of it all, only you can truly gauge what you need to learn and what you need to do next. The only way you can be happy with your work as a web developer is if you build stuff you actually want to! Might seem trivial, but it can go a long way. Oh and by the way, the journey that I've tried to convey in this post, is one that I have happened to go through, that may not accurately describe yours, &lt;b&gt;but that was the entire point of this post!&lt;b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/p&gt;

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