<?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: Rishav Jadon</title>
    <description>The latest articles on DEV Community by Rishav Jadon (@rjitsu).</description>
    <link>https://dev.to/rjitsu</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%2F452153%2F173c1288-ce90-4b46-82f6-edd8bd6f6dd1.png</url>
      <title>DEV Community: Rishav Jadon</title>
      <link>https://dev.to/rjitsu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rjitsu"/>
    <language>en</language>
    <item>
      <title>How does JS execute "use strict"?</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Sun, 23 Jan 2022 07:43:11 +0000</pubDate>
      <link>https://dev.to/rjitsu/how-does-js-execute-use-strict-26cd</link>
      <guid>https://dev.to/rjitsu/how-does-js-execute-use-strict-26cd</guid>
      <description>&lt;p&gt;I'm curious if anyone knows what goes on &lt;strong&gt;behind the scenes&lt;/strong&gt; when we write "use strict" in a JS script?&lt;/p&gt;

&lt;p&gt;So in use strict we:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cannot use undeclared variables.&lt;/li&gt;
&lt;li&gt;that means no &lt;strong&gt;hoisting&lt;/strong&gt;. How is that handled🤔? &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>discuss</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Star Rating system with HTML, CSS,JS </title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Fri, 14 Jan 2022 14:01:36 +0000</pubDate>
      <link>https://dev.to/rjitsu/star-rating-system-with-html-cssjs-594k</link>
      <guid>https://dev.to/rjitsu/star-rating-system-with-html-cssjs-594k</guid>
      <description>&lt;p&gt;In a very minimal way,  how would you implement a star rating system?&lt;br&gt;
I was able to do it 😁 Here is my code, corrections are welcome :) &lt;br&gt;
&lt;a href="https://codepen.io/Rj456/pen/dyVwgbX?editors=0011"&gt;https://codepen.io/Rj456/pen/dyVwgbX?editors=0011&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>codepen</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>How do you create a Redux store for Login functionality?</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Tue, 21 Dec 2021 14:29:06 +0000</pubDate>
      <link>https://dev.to/rjitsu/how-do-you-create-a-redux-store-for-login-functionality-10fb</link>
      <guid>https://dev.to/rjitsu/how-do-you-create-a-redux-store-for-login-functionality-10fb</guid>
      <description>&lt;p&gt;How do you think when you have states for email, password, and other states like dateRange values, and you have to implement a Redux store for them?&lt;br&gt;
What kind of action creators do you write, should you use Redux toolkit, and what's the most simplest way to do this?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>javascript</category>
      <category>redux</category>
      <category>react</category>
    </item>
    <item>
      <title>Stop using if else </title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Thu, 14 Oct 2021 12:34:45 +0000</pubDate>
      <link>https://dev.to/rjitsu/stop-using-if-else-264o</link>
      <guid>https://dev.to/rjitsu/stop-using-if-else-264o</guid>
      <description>&lt;p&gt;Recently, I had a take home assignment for a front end role, and I had to make a sort of Dashboard. I thought I did everything right,  but I was rejected,  partly on my carelessness, and also due to my code. I was using too many if/else statements everywhere! And I didn't know any better. But now I do, and I'm here to share that with you.&lt;/p&gt;

&lt;p&gt;Most of us use if/else and switch statements whenever there is some conditional logic to handle. Although it might be a good idea to do that for one or two conditions here and there, using multiple if else statements chained together or big switch statements will make your code look very ugly, less readable and error prone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;whoIsThis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;naruto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Hokage`&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sasuke&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Konoha's Strongest Ninja`&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;isshiki&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Otsutsuki being`&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;boruto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Naruto and Hinata's son`&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;whoIsThis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see that we are repeating ourselves many times by writing multiple console.logs and if statements.&lt;/p&gt;

&lt;p&gt;But there's an Object-Oriented way of doing this, and that is by using Objects.&lt;br&gt;
Instead of writing if else blocks we just define an object which has the values we use in comparisons as keys, and the values we return as values of the objects, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;whoIsThis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;listOfCharacters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;naruto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Hokage`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sasuke&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Konoha's Strongest Ninja`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;isshiki&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Otsutsuki being`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;boruto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Naruto and Hinata's son`&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;listOfCharacters&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;`Please provide a valid character name`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using objects, we were able to make a sort of dictionary to look up to, and not use multiple if-else statements. &lt;/p&gt;

&lt;p&gt;We can also make this better by using the &lt;strong&gt;Map&lt;/strong&gt; object instead of using an object. Maps are different from normal objects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They remember the original order of insertion&lt;/li&gt;
&lt;li&gt;Unlike objects, we can use any type of data as key/value, not just strings, numbers and symbols.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;whoIsThis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapOfCharacters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;naruto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Hokage`&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sasuke&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Konoha's Strongest Ninja`&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;isshiki&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Otsutsuki being`&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;boruto&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Naruto and Hinata's son`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;mapOfCharacters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="s2"&gt;`Please provide a valid character name`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading this short article, if you liked it, you can support my work at &lt;a href="https://www.buymeacoffee.com/rishavjadon"&gt;https://www.buymeacoffee.com/rishavjadon&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>oop</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The only guide you'll ever need to understand Promises and Async await</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Tue, 12 Oct 2021 11:26:49 +0000</pubDate>
      <link>https://dev.to/rjitsu/the-only-guide-you-ll-ever-need-to-understand-promises-and-async-await-24cd</link>
      <guid>https://dev.to/rjitsu/the-only-guide-you-ll-ever-need-to-understand-promises-and-async-await-24cd</guid>
      <description>&lt;p&gt;&lt;em&gt;When it comes to **Promises&lt;/em&gt;* and &lt;strong&gt;Async await&lt;/strong&gt; which are closely related concepts in Javascript, people are always confused even after watching tutorials or reading numerous articles about them. Well, worry not because I assure you if you read this article thoroughly you will have a better understanding of what they are and how they work.*&lt;/p&gt;

&lt;h2&gt;
  
  
  The Evolution of Asynchronous programming
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bsyegk_1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1634034480012/0Fo-g5FWF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bsyegk_1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1634034480012/0Fo-g5FWF.png" alt="Untitled-2021-10-12-1403.png" width="880" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callback functions --&amp;gt; Promises --&amp;gt; Async await&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Don't worry, we will understand what this evolution is all about and why it took place, further in the article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript is synchronous, or is it?
&lt;/h2&gt;

&lt;p&gt;Javascript is a &lt;strong&gt;synchronous&lt;/strong&gt; language, meaning that every statement is &lt;strong&gt;run line by line&lt;/strong&gt; in a sequential manner, and only when a line of code is done being executed is when the next line will run. &lt;/p&gt;

&lt;p&gt;Now, what if something takes a long time to execute than usual, and it blocks the whole program? This is bad, we don't want to slow down our program just because a single line of code (which might be an API call to get an image resource) is blocking our entire script. &lt;br&gt;
That is why we needed &lt;strong&gt;asynchronous code&lt;/strong&gt;, which does not block the code after it, and can run in the background. There are a lot of ways we can do asynchronous programming in JavaScript:  callback functions,  Promises and Async await.&lt;/p&gt;
&lt;h2&gt;
  
  
  Callback functions
&lt;/h2&gt;

&lt;p&gt;Callback functions are basically functions passed to functions as arguments to be executed later, and they can be synchronous or asynchronous. One most popular example of this is the s*&lt;em&gt;etTimeout&lt;/em&gt;* function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code does a console.log after 500 milliseconds and runs asynchronously. &lt;br&gt;
A synchronous callback function might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [ 1, 2, 3, 4, 5, 6, 7 ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function sort() has an anonymous arrow function that works as a callback to sort the array, and we print it on the console. &lt;br&gt;
Notice that the arrow function runs &lt;strong&gt;before&lt;/strong&gt; the console and therefore we get the sorted array, but if you would have sorted the same array with a setTimeout then the console will print unsorted array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;// numbers.sort((a, b) =&amp;gt; a - b)&lt;/span&gt;
&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;// console.log(numbers)&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [2, 1, 4, 7, 3, 5, 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because asynchronous code runs after all synchronous code is finished executing, that is why even though the setTimeout had 0 wait time, it still ran after the console.log, even though console.log comes later in code. &lt;/p&gt;

&lt;p&gt;Callbacks are good for asynchronous programming as long as you have very few async actions, but if you want to run more functions asynchronously, then callbacks become an ugly mess!  &lt;/p&gt;

&lt;p&gt;Imagine if you have a number of requests and you want to run them in callback functions. The code might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://fakeapi.com/1/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://fakeapi.com/2/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://fakeapi.com/3/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="c1"&gt;// calls api here&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;first message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;second message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;third message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// first message&lt;/span&gt;
&lt;span class="c1"&gt;// second message&lt;/span&gt;
&lt;span class="c1"&gt;// third message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These nested callbacks create what is infamously called the &lt;strong&gt;Callback Hell&lt;/strong&gt;, and this  type of code can become unmaintainable very quickly. &lt;br&gt;
To solve this, &lt;strong&gt;Promises&lt;/strong&gt; were introduced in ES6( Ecmascript 2015).&lt;/p&gt;
&lt;h2&gt;
  
  
  All these Promises you do
&lt;/h2&gt;

&lt;p&gt;Promises in JS are like promises in real life, it either is &lt;strong&gt;resolved&lt;/strong&gt; or &lt;strong&gt;never&lt;/strong&gt; completed.&lt;br&gt;
There are certain things you need to know to understand Promises better. A Promise can be in one of the three states: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;resolved&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;rejected&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;pending&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Promise objects can be made by the &lt;strong&gt;Promise() constructor&lt;/strong&gt;, which takes in an &lt;strong&gt;executor&lt;/strong&gt; function, which in turn takes two functions as parameters: a &lt;strong&gt;resolve&lt;/strong&gt; function and a &lt;strong&gt;reject&lt;/strong&gt; function.&lt;br&gt;
This is how you make a new promise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;aPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;promise resolved&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;aPromise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This "executor" function terminates with the invocation of resolve or reject function depending on the value of the Promise, meaning that the executor function runs some code,  and calls resolve function if the Promise gets resolved or reject function if it throws an error.&lt;/p&gt;

&lt;p&gt;After your promise is resolved or rejected you can chain it with the methods &lt;strong&gt;.then()&lt;/strong&gt; and &lt;strong&gt;.catch()&lt;/strong&gt; respectively. These methods themselves return Promises. &lt;br&gt;
You can also chain multiple .then() methods to modify the value that comes back from a resolved Promise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;aPromise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;changed value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dd4cGiuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1634036850044/s5oO_7mLo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dd4cGiuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1634036850044/s5oO_7mLo.png" alt="promise.png" width="880" height="541"&gt;&lt;/a&gt;&lt;br&gt;
We usually use these methods while making an api call. &lt;br&gt;
Let's use the fetch API to fetch list of Pokemon from the PokeAPI. The fetch(). function returns a Promise so we can attach our .then() and .catch() methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://pokeapi.co/api/v2/pokemon?limit=100&amp;amp;offset=200&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give us a list of 100 Pokemon with other properties. Promises did make our lives easier but our code still looks like it's bulky with all these chaining methods. &lt;strong&gt;Async await&lt;/strong&gt; made this much more cleaner and allowed us to write asynchronous code that looked very much like our good old synchronous code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Async await
&lt;/h2&gt;

&lt;p&gt;Remember that Async await is kinda like Classes in Javascript, it might look like we are writing entirely different code, but under the hood, we are still using Promises. It's just that the syntax and readability got better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Async await&lt;/strong&gt; is used in place of &lt;strong&gt;.then()&lt;/strong&gt; and .&lt;strong&gt;catch()&lt;/strong&gt; when working with &lt;strong&gt;Promises&lt;/strong&gt;. We need to assign a function ASYNC and then inside of it we can have the await keyword before the asynchronous actions we'd like to perform ( meaning the code we think might take longer time). Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/1/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;loadData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can you see the difference between this and Promises? This is so much cleaner and doesn't even look like we are doing something asynchronously. Just define an async function and add await before anything you'd want to run asynchronously. &lt;/p&gt;

&lt;p&gt;Using async on a function, with await inside on any operation( like an API call) will say to JS : &lt;em&gt;"Hey man just don't return this function until this thing with the await is done, after that do whatever you gotta do"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Things to remember about Async await:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;always assign the function you want to have asynchronous code in as an &lt;strong&gt;async&lt;/strong&gt; function.&lt;/li&gt;
&lt;li&gt;you can only use &lt;strong&gt;await&lt;/strong&gt; inside of an async function.&lt;/li&gt;
&lt;li&gt;An async function returns a &lt;strong&gt;Promise&lt;/strong&gt;,  so you can chain multiple async functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  try-catch block
&lt;/h2&gt;

&lt;p&gt;Just like the .catch() block we used in Promises, we use &lt;strong&gt;try-catch&lt;/strong&gt; for error handling in Async await. This makes the code much cleaner and more organized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/1/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Async functions also return a promise.  So get this, a fetch or an Axios request returns a promise,  an async function also returns a promise. We can either do a .then() chaining or another async await on a Promise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Promise.all()
&lt;/h2&gt;

&lt;p&gt;If you need to make multiple requests to an API, and you go by the approach of async await,  it will take the sum of time it takes for all requests to return data. So let's say each request takes 1 sec, and for 3 requests, we will have to wait 3 secs if we just await on every single request like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Wrong approach */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/1/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/2/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/3/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;strong&gt;Promise.all()&lt;/strong&gt;,  each request runs parallel to each other, resulting in a much quicker response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Right approach */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/1/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/2/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.com/todos/3/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataPromises&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;finalData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataPromises&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;finalData&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;loadData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all. We learned a lot of things, what is asynchronous programming, how do callback functions work,  about Promises and Async await.&lt;/p&gt;

&lt;p&gt;For further reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://javascript.info/async"&gt;https://javascript.info/async&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;If you like my work you can support me on &lt;a href="https://www.buymeacoffee.com/rishavjadon"&gt;https://www.buymeacoffee.com/rishavjadon&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Windows or Linux/Mac : which one is better for development?</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Fri, 29 Jan 2021 16:08:56 +0000</pubDate>
      <link>https://dev.to/rjitsu/windows-or-linux-mac-which-one-is-better-for-development-1n73</link>
      <guid>https://dev.to/rjitsu/windows-or-linux-mac-which-one-is-better-for-development-1n73</guid>
      <description>&lt;p&gt;Which one is better in terms of workflow, developer experience, etc?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Stop being lazy and learn Git!</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Tue, 26 Jan 2021 13:21:06 +0000</pubDate>
      <link>https://dev.to/rjitsu/stop-being-lazy-and-learn-git-5083</link>
      <guid>https://dev.to/rjitsu/stop-being-lazy-and-learn-git-5083</guid>
      <description>&lt;p&gt;"I have never messed up while using git" - said no one, ever.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git&lt;/strong&gt; is something that if learned properly in beginning of your career as a software engineer, can serve you so well in the coming years!&lt;/p&gt;

&lt;p&gt;Hey there 👋 I'm Rishav, and this is my new article series called "Bookmark Devouring🔖🥩" in which I will clear all my bookmarks on all platforms and in the process, learn new things and teach you too!&lt;/p&gt;

&lt;p&gt;In this article, we will learn about the most popular "version control system" that is &lt;strong&gt;git&lt;/strong&gt;. At the end of this article, &lt;strong&gt;you will have a solid understanding of how git works, the problems we might face,  and how to fix those problems.&lt;/strong&gt;&lt;br&gt;
Let's eat a potato like Sasha and start!&lt;br&gt;
&lt;a href="https://i.giphy.com/media/2EQ7NCJZhI8iQ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/2EQ7NCJZhI8iQ/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Short Intro to Git 🖧
&lt;/h1&gt;

&lt;p&gt;Git is a &lt;strong&gt;distributed version control system&lt;/strong&gt;. Okay what? Let me break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;distributed&lt;/strong&gt; 
meaning all our code, including full history of changes is mirrored on each user's computer. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;version control system&lt;/strong&gt;
keeps track of the project files, history of changes, support for branching, merging and other things. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a different kind too, called &lt;strong&gt;Centralized VCS&lt;/strong&gt; in which all code is stored on a server, and people (clients) pull code from server, make their changes, and then push changes directly to server. So there is no collaboration with other developers, and only connection is with the server. &lt;/p&gt;

&lt;p&gt;We use git for project management and efficient, error free collaboration with other developers. Storing code change history and using features such as branching helps us for better &lt;strong&gt;collaboration&lt;/strong&gt;,  which is one of the most important aspects of programming.&lt;/p&gt;

&lt;p&gt;Before getting into why is git needed, and the problems it solves, we need to understand some basic concepts about git.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Repository&lt;/strong&gt;: A repository is the place where all your project files will be stored along with a .git folder containing all the stuff git records. We have &lt;strong&gt;local&lt;/strong&gt; and &lt;strong&gt;remote&lt;/strong&gt; repositories. Local ones are saved in our own system, whereas remote repositories are hosted online on platforms like &lt;em&gt;Github, Gitlab, etc.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commits&lt;/strong&gt;: When you make changes into your code or add/delete files, you need to &lt;strong&gt;commit&lt;/strong&gt; the changes to the branch you are in. You can think of this as saving your work in git history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Branching and Merging&lt;/strong&gt;: All work is done on branches. After you have just initialized your git repository, everything will be saved in the default &lt;strong&gt;Master Branch&lt;/strong&gt;. If you want to work on some features and don't want to mess your main codebase, you create a branch. After working on the features ,when you want to add your changes to master branch, you merge the two branches.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Staging Area&lt;/strong&gt;: Before commiting changes, we need to add it to the Staging area. This tells git to commit all those changes which are &lt;strong&gt;staged&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Why git?
&lt;/h1&gt;

&lt;p&gt;Git is cool but why do we need it? We will look into the story of Sasha, retired Survey Corps soldier transitioning into tech. &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.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1611572305043%2FNJIJbcFZa.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.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1611572305043%2FNJIJbcFZa.png" alt="Facebook post - 1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sasha is a newbie developer and is assigned to a new project at work. It is an ongoing project so she takes all the project codebase and copies into her personal system and takes it home. She happily works on all the things she were assigned to, and later comes back with her copy of the project,  which has changes of her own. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But there were other newbies too, and they were all assigned to this project and they had changes of their own. What a disaster! How do we solve this? Everybody has a different copy of the project, and all of those changes need to be done in the main project. Some changes might conflict with other changes, like the same file having different code from the actual onsite project,  and some files might be deleted by the newbies which we don't really want. &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.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1611573709277%2Ff37HzytNt.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.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1611573709277%2Ff37HzytNt.png" alt="Facebook post - 2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike all the other newbies,  Sasha did some research, and found out about this open source tool called Git. She told all the other newbies that we can collaborate and merge our changes into the main project hassle free with Git. She gave some instructions to everyone on how to work with git. &lt;/p&gt;
&lt;h1&gt;
  
  
  Initial Steps
&lt;/h1&gt;

&lt;p&gt;Sasha told everyone to go home and taught them some basic commands. But before that they needed to install Git. She gave them this &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;link&lt;/a&gt;. After installing git, they were told to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in their working directory. This will initialize a new git repository(aka directory aka folder),  and from here git will start recording changes. Now what we need is &lt;strong&gt;get local copy of our main project&lt;/strong&gt;, which is on a &lt;strong&gt;public remote repository&lt;/strong&gt;(stored on Github). On the repo webpage of this remote repo(we'll call it repo instead of repository), we will see a link to clone their webpage:&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.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1611647810298%2Fv7ll8iFZe.jpeg" 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.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1611647810298%2Fv7ll8iFZe.jpeg" alt="Screenshot (888)_LI.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy this https url and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/rjitsu/CSS-Cheat-Sheet.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will clone( download ) the repo in our system. Now that everyone has the fresh copy of project, they can work on it as they want and make their changes. &lt;/p&gt;

&lt;p&gt;"But how?" - asked one newbie to Sasha. &lt;/p&gt;

&lt;h1&gt;
  
  
  Branching and collaborating
&lt;/h1&gt;

&lt;p&gt;Git has a feature called &lt;strong&gt;Branching&lt;/strong&gt; for safe collaboration. When you create a git repo,  and work on it without branching, by default all changes are done to &lt;strong&gt;Master branch&lt;/strong&gt;. When you want to add a feature,  or just work seperately so that if you mess up, the master branch will not be affected, you make a branch. You do it by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch new-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new branch. To see all branches, you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will list all repositories. But git branch new-branch does not switch to the newly made branch, it just makes it. So to switch to it we use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout new-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay. Now we have a new branch. We make our changes to the code. Now we want to &lt;strong&gt;stage&lt;/strong&gt; them and &lt;strong&gt;commit&lt;/strong&gt; them. To stage all files we run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The " . " is depicting we need to stage all files to the &lt;strong&gt;staging area&lt;/strong&gt;. If you just need to stage some particular files, you do &lt;code&gt;git add&lt;/code&gt; following the filenames. To commit files and finally save them in our history we run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "add all files"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The -m flag is for adding a commit message which is followed by the message itself. If you omit the -m flag, &lt;code&gt;git commit&lt;/code&gt; will open a text editor to add the commit message.&lt;br&gt;&lt;br&gt;
You can watch all commits done on the branch you are on by :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Hot Tip 🔥: use &lt;code&gt;git log --decorate --oneline --graph --all&lt;/code&gt; to see a cleaner and prettier git log output&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we will &lt;strong&gt;push our code&lt;/strong&gt; to our branch by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now,  you need to merge your branch to the master. Before that, you checkout to the master branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge new-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a &lt;strong&gt;merge commit&lt;/strong&gt; in git history, and will merge your branch into the master, meaning all your changes including history of changes is added to the master branch.&lt;/p&gt;

&lt;p&gt;Hooray! Your branch is merged with the master branch. But all these changes are on our local repository with no connection to our main project which is hosted on a remote repository online on Github 😱.&lt;/p&gt;

&lt;p&gt;Turns out we already created a connection with our remote repository when we ran &lt;code&gt;git clone&lt;/code&gt;. Some commands in git are like a list of commands run together one by one. For example, when we ran &lt;code&gt;git clone&lt;/code&gt;, it ran these commands as well&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
git remote add origin https://github.com/rjitsu/CSS-Cheat-Sheet.git
git pull origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now push all your changes by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will push all the changes from your local master branch to the origin.&lt;br&gt;
Phew!&lt;/p&gt;

&lt;p&gt;Sasha explained all this to the newbies, and therefore they could all work hassle free on their local branches via git!&lt;/p&gt;

&lt;p&gt;If you read through all that, congratulations to you🎉.&lt;br&gt;&lt;br&gt;
To recap, we learned about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what git is, the important terms related to it.&lt;/li&gt;
&lt;li&gt;how to initialize, add, commit and push to branches.&lt;/li&gt;
&lt;li&gt;how to merge branches.&lt;/li&gt;
&lt;li&gt;a git workflow describing a real life situation of Sasha👧&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading. If you liked this article, be sure to check my other ones too!&lt;br&gt;
For further reading,  read the docs on &lt;a href="https://www.atlassian.com/git/tutorials" rel="noopener noreferrer"&gt;Atlassian&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Can css art and generative art be considered as projects to put on a portfolio?</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Thu, 08 Oct 2020 14:02:36 +0000</pubDate>
      <link>https://dev.to/rjitsu/can-css-art-and-generative-art-be-considered-as-projects-to-put-on-a-portfolio-1n4d</link>
      <guid>https://dev.to/rjitsu/can-css-art-and-generative-art-be-considered-as-projects-to-put-on-a-portfolio-1n4d</guid>
      <description>

</description>
      <category>discuss</category>
      <category>css</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Introduction to creative coding with p5.js</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Tue, 06 Oct 2020 12:10:18 +0000</pubDate>
      <link>https://dev.to/rjitsu/introduction-to-creative-coding-with-p5-js-5a15</link>
      <guid>https://dev.to/rjitsu/introduction-to-creative-coding-with-p5-js-5a15</guid>
      <description>&lt;p&gt;&lt;em&gt;"Creating a process which makes the process"&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Creative coding is addictive, if you really tune into it! It has immense possibilities, and that is why I decided to write this article, to introduce all of you to this wonderful genre of coding with a Javascript library called &lt;strong&gt;p5.js&lt;/strong&gt;, where you can communicate to your audience more artistically than ever before!&lt;/p&gt;
&lt;h1&gt;
  
  
  What is creative coding?
&lt;/h1&gt;

&lt;p&gt;In my terms, creative coding is just making some art, pattern, background, models, sketches, data visualization, animation, etc with the help of code, in a sort of iterative way to express something. It is about creating something expressive rather than functional, with code. Creative coding is a discipline which is an intersection of technology, art and design.&lt;br&gt;&lt;br&gt;
Didn't get it? Let me show you some examples. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601969117%2FDEV%2Fccss_image_ibvwo9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601969117%2FDEV%2Fccss_image_ibvwo9.jpg" alt="Image 1"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601969124%2FDEV%2F180827_Sphere3D_frame-000125_ofqmze.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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601969124%2FDEV%2F180827_Sphere3D_frame-000125_ofqmze.png" alt="Image 2"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601969076%2FDEV%2Funnamed_dl8nf3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601969076%2FDEV%2Funnamed_dl8nf3.jpg" alt="Image 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You must be thinking right now : "Whattt? These art forms are made from 'code'? I can't believe it! ". That's what I initially thought, but once you get into this beautiful practice, you'll start to understand how nature itself is just a bunch of repetitive processes which ultimately makes this world, which is kinda what we do in coding, right? We create an algorithm, to solve our problems. The only thing that changes in creative coding is that we create algorithms for expressing something, in the form of art.&lt;/p&gt;
&lt;h1&gt;
  
  
  p5.js
&lt;/h1&gt;

&lt;p&gt;You could do creative coding with C++ too! But it's not meant for that, that's why we have frameworks specifically for creative coding. &lt;a href="https://processing.org/" rel="noopener noreferrer"&gt;Processing&lt;/a&gt; is the most famous platform for this, and it uses Java, but it has other variants for other languages as well, and &lt;a href="https://p5js.org/" rel="noopener noreferrer"&gt;p5.js&lt;/a&gt; is the platform we use for creative coding on the web. It obviously, uses Javascript, so it is very easy for web developers to get started with this, which was the primary reason it was made by &lt;a href="https://lauren-mccarthy.com/" rel="noopener noreferrer"&gt;Lauren McCarthy&lt;/a&gt;. So let's just get started. &lt;br&gt;&lt;br&gt;
For a quickstart, just open the &lt;a href="https://editor.p5js.org/" rel="noopener noreferrer"&gt;p5.js web editor&lt;/a&gt;. Now that you have a p5 editor, let's get into some code. So, there are &lt;strong&gt;two functions&lt;/strong&gt; that are most important in p5:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;setup()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;draw()&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So setup() is an inbuilt function which runs only once, at the start of the program, and draw() is also an inbuilt function which runs on loop, which means it runs infinitely by default. Let's understand them individually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. function setup()&lt;/strong&gt;&lt;br&gt;
This is the function in which we put all the things that we want to do initially and only once. It basically sets up the environment and things like screen size, background color, for our &lt;strong&gt;"sketch"&lt;/strong&gt; : which is what we call our program files in p5.js. A very generic setup function looks like this: &lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setup(){
 createCanvas(500,500);
 background(120);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, we have a function &lt;code&gt;createCanvas()&lt;/code&gt;, which creates a canvas of 500x500 units, and a &lt;code&gt;background()&lt;/code&gt; function, which sets up the color for our canvas. If we provide a single argument, it will be a value from 0 to 255, 0 being black and 255 white. If we provide three arguments, it will use RGB color notation, each value ranging from 0 to 255. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. function draw()&lt;/strong&gt;&lt;br&gt;
This is where most of the action happens. Here we use various functions, loops, and self made algorithms to make our final artwork. You can work with sound, data, webcams, sensors, and other things to interpolate in your sketch to make it interactive, but that is out of scope of this article. So if we wanna draw a line, circle, rectangle or any shape, we have functions for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function draw(){
  fill(233,11,44); // color to fill the shapes
  stroke(1); // stroke color
  strokeWeight(2);
  line(20,20,160,60); // line from (20,20) to (160,60)
  fill(23,44,223); 
  rect(170,170,120,70); // rectangle on (170,170) with 120x70 size
  fill(223,212,44);
  ellipse(120,130,100,100); // ellipse on (120,130) with height 100 and width 100, which makes it a circle
  noLoop();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the code above will produce something like this: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601980157%2FDEV%2Fa_1_ozmhdz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601980157%2FDEV%2Fa_1_ozmhdz.jpg" alt="Sketch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The functions are self explanatory, and by the comments you might have understood what's going on. There was one function at the end called &lt;strong&gt;noLoop()&lt;/strong&gt; , which actually does nothing but stops the draw() function from running infinitely. This is useful in scenarios where you might want to run &lt;code&gt;draw()&lt;/code&gt; for a particular number of times.&lt;br&gt;&lt;br&gt;
There are some &lt;strong&gt;inbuilt&lt;/strong&gt; variables in p5 too, which can add complexity to our sketches. Some of them are &lt;strong&gt;mouseX&lt;/strong&gt; and &lt;strong&gt;mouseY&lt;/strong&gt;. They are variables used to store x and y co-ordinates of the mouse cursor.&lt;br&gt;
Look at this sketch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setup() {
  createCanvas(400, 400);
  background(200);
}
function draw(){
  fill(233,11,44);
  stroke(1); 
  strokeWeight(2);
  makeShapes();
}
function makeShapes(){
  fill(random(200),random(200),random(200));
  ellipse(mouseX,mouseY,50,50);
  rect(mouseX,mouseY,120,70);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601982117%2FDEV%2Fscreen-capture_19_cp63sl.gif" 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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601982117%2FDEV%2Fscreen-capture_19_cp63sl.gif" alt="Sketch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The possibilities
&lt;/h1&gt;

&lt;p&gt;As this is just to introduce you to p5.js, I can't go into complex sketches but I've laid down a path for you, and hopefully you'll create some beautiful things after venturing into the art of creative coding. For inspiration, here are some of my sketches :)&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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601983456%2FDEV%2Fscreen-capture_20_dctgcb.gif" 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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601983456%2FDEV%2Fscreen-capture_20_dctgcb.gif" alt="BLOOMING SHAPES"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601983920%2FDEV%2FScreenshot_624_ldth5b.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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601983920%2FDEV%2FScreenshot_624_ldth5b.png" alt="Alternate Dimensions"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601984167%2FDEV%2FScreenshot_627_hwttve.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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601984167%2FDEV%2FScreenshot_627_hwttve.png" alt="Triangles"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601984867%2FDEV%2FScreenshot_630_mqshnd.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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1601984867%2FDEV%2FScreenshot_630_mqshnd.png" alt="Oblivion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you've reached till here, thank you for reading! Hope it helped you in some way. If you're interested in CSS, I also write some interesting articles on my website &lt;a href="https://www.csskenpai.com/" rel="noopener noreferrer"&gt;CSS Kenpai&lt;/a&gt;.&lt;br&gt;
Some sources for further reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/better-programming/getting-started-with-creative-coding-16072ff7e778" rel="noopener noreferrer"&gt;https://medium.com/better-programming/getting-started-with-creative-coding-16072ff7e778&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://p5js.org" rel="noopener noreferrer"&gt;https://p5js.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.creativebloq.com/features/6-ways-to-get-into-creative-coding" rel="noopener noreferrer"&gt;https://www.creativebloq.com/features/6-ways-to-get-into-creative-coding&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>codepen</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Make Pixel art 10x faster ✨💫</title>
      <dc:creator>Rishav Jadon</dc:creator>
      <pubDate>Tue, 25 Aug 2020 14:05:01 +0000</pubDate>
      <link>https://dev.to/rjitsu/make-pixel-art-10x-faster-5ck</link>
      <guid>https://dev.to/rjitsu/make-pixel-art-10x-faster-5ck</guid>
      <description>&lt;p&gt;&lt;strong&gt;You'll never have to use the box-shadows again&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So this article will be short and simple so you can just take this technique and start making wonderful pixel art!&lt;br&gt;
Before stumbling on this, I used to make pixel art with &lt;code&gt;box-shadow&lt;/code&gt;, and it is so painful! Just copy pasting values and then changing the values again and again.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Rj456/embed/WNrMNKE?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you're unfamiliar with making pixel art with box-shadows, I'll just give you a small introduction. &lt;code&gt;box-shadow&lt;/code&gt; is a property in css which attaches one or more shadows to the element it is applied on. So if you want to make pixel art , you just create a small box, and then define ( a lot ) of box-shadows positioned differently around the screen so that you can create a nice pixel art like effect.&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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1598362679%2FbCiQc8dESeWm_1_qin5u4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1598362679%2FbCiQc8dESeWm_1_qin5u4.jpg" alt="box-shadow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Problem with the box-shadow
&lt;/h1&gt;

&lt;p&gt;By now you also might be able to see the problem in &lt;code&gt;box-shadow&lt;/code&gt; which is the sheer work. Defining each &lt;code&gt;box-shadow&lt;/code&gt; again and again is just too much work! Now you might be thinking why even bother making pixel art from code, as there are multitude of software like &lt;a href="https://twitter.com/jh3yy" rel="noopener noreferrer"&gt;Jhey Tompkin's&lt;/a&gt; &lt;a href="https://pxl.netlify.app/" rel="noopener noreferrer"&gt;pxl&lt;/a&gt;. My answer to that is &lt;strong&gt;CREATIVITY&lt;/strong&gt;. Things like pure CSS art, one div art, no div art, and pixel art are not for any productive purpose, it's for the purpose of showing your personality,creativity,imagination, and in this process you learn the deeper concepts more clearly! &lt;/p&gt;

&lt;h1&gt;
  
  
  The answer is in CANVAS
&lt;/h1&gt;

&lt;p&gt;When &lt;code&gt;box-shadow&lt;/code&gt; is too much of a hassle, use &lt;strong&gt;canvas!&lt;/strong&gt;. I always use a reference image. We will use this image for the purpose of this article. &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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1598363669%2Fhamster_gvoz7f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1598363669%2Fhamster_gvoz7f.jpg" alt="Reference Image of a hamster"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The basic idea is : &lt;strong&gt;We will use the canvas API in javascript and will define our pixels by making a 2-D array, which will have our pixel values mapped perfectly along each row, and then we will fill our canvas by using nested for loops and taking values from array and fill in canvas pixel by pixel. This is much faster in comparision to the box-shadows technique!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let me show you how to do it with a step-by-step approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 : Set up our canvas
&lt;/h2&gt;

&lt;p&gt;Make a canvas in your HTML of any size you want.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;canvas height="500" width="500" id="board"&amp;gt;
&amp;lt;/canvas&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 2 : Set up variables
&lt;/h2&gt;

&lt;p&gt;We need to make variables for the size of pixels, for colors you will use in making your art. We will do this in our JS file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var pixelSize = 15;
var _ = "transparent",
         b = "#000000",
         o = "orange",
         p = "hotpink"; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Step 3 : Define our array
&lt;/h1&gt;

&lt;p&gt;Now we need to fill these color values into our array according to our reference image. Just count how many pixels we need by row and by column, and we will make our grid accordingly.&lt;br&gt;
Here, we need a 30 x 30 pixel grid ,so we will define an array which has 30 color values in a column, and we'll make 30 of those rows.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var image = [
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, b, b, b, b, _, _, _, _, _, _, _, _, _, _, _, b, b, b, b, _, _, _, _, _, _],
[_, _, _, b, o, o, o, o, b, _, _, _, _, _, _, _, _, _, b, o, o, o, o, b, _, _, _, _, _],
[_, _, b, p, b, b, o, o, o, b, _, _, _, _, _, _, _, b, o, o, o, b, b, p, b, _, _, _, _],
[_, _, b, p, p, p, b, o, o, b, b, b, b, b, b, b, b, b, o, o, b, p, p, p, b, _, _, _, _],
[_, _, b, p, p, p, b, o, o, o, o, o, o, o, o, o, o, o, o, o, b, p, p, p, b, _, _, _, _],
[_, _, b, p, p, b, o, o, o, o, o, o, o, o, o, o, o, _, _, _, _, b, p, p, b, _, _, _, _],
[_, _, _, b, b, o, o, o, o, o, o, o, o, o, _, _, _, _, _, _, _, _, b, b, _, _, _, _, _],
[_, _, _, _, b, o, o, b, b, b, o, o, _, _, _, _, _, b, b, b, _, _, b, _, _, _, _, _, _],
[_, _, _, _, b, o, b, b, _, _, b, _, _, _, _, _, b, _, _, b, b, _, b, _, _, _, _, _, _],
[_, _, _, b, o, o, b, b, _, _, b, _, _, _, _, _, b, _, _, b, b, _, _, b, _, _, _, _, _],
[_, _, _, b, _, _, b, _, b, b, b, _, _, _, _, _, b, b, b, _, b, _, _, b, _, _, _, _, _],
[_, _, _, b, b, _, _, b, b, b, _, _, _, _, _, _, _, b, b, b, _, _, b, b, _, _, _, _, _],
[_, _, _, b, _, _, _, _, _, _, _, _, _, b, _, _, _, _, _, _, _, _, _, b, _, _, _, _, _],
[_, _, _, b, b, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, b, b, _, _, _, _, _],
[_, _, _, b, _, _, _, _, _, _, b, _, _, b, _, _, b, _, _, _, _, _, _, b, _, _, _, _, _],
[_, _, _, _, b, _, _, _, _, _, _, b, b, _, b, b, _, _, _, _, _, _, b, _, _, _, _, _, _],
[_, _, _, _, b, b, o, o, _, _, _, _, _, _, _, _, _, _, o, o, b, b, b, _, _, _, _, _, _],
[_, _, _, _, b, o, o, _, _, b, _, _, _, _, _, _, _, b, _, _, o, o, b, _, _, _, _, _, _],
[_, _, _, _, b, o, o, _, p, p, b, _, _, _, _, _, b, p, p, _, o, o, b, _, _, _, _, _, _],
[_, _, _, _, b, o, _, b, p, p, b, _, _, _, _, _, b, p, p, b, _, o, b, _, _, _, _, _, _],
[_, _, _, _, b, _, _, _, b, b, _, _, _, _, _, _, _, b, b, _, _, _, b, _, _, _, _, _, _],
[_, _, _, _, _, b, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, b, _, _, _, _, _, _, _],
[_, _, _, _, _, _, b, _, _, _, b, b, b, b, b, b, b, _, _, _, b, _, _, _, _, _, _, _, _],
[_, _, _, _, _, b, p, p, b, b, _, _, _, _, _, _, _, b, b, p, p, b, _, _, _, _, _, _, _],
[_, _, _, _, _, _, b, b, _, _, _, _, _, _, _, _, _, _, _, b, b, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It looks like a really big array, but trust me, if you know the pain of making pixel art by box-shadows, this will definitely help a lot! &lt;/p&gt;

&lt;h1&gt;
  
  
  Step 4: Filling our canvas
&lt;/h1&gt;

&lt;p&gt;The only thing left to do is fill the canvas by applying nested &lt;code&gt;for&lt;/code&gt; loops, and filling our pixels by the colors in our array. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var canvas = document.getElementById('board');
var ctx = canvas.getContext('2d');
ctx.lineWidth = .25;
for(var i=0;i&amp;lt;29;i++) {
 for(var j=0;j&amp;lt;29;j++) {
   ctx.fillStyle = image[j][i];
   ctx.fillRect(i*pixelSize, j*pixelSize, pixelSize, pixelSize);
     }
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After positioning our canvas, and adding some styling to it, the finished art looks like this: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1598363905%2FScreenshot_507_jhmmgq.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%2Fres.cloudinary.com%2Fcodepenrishav%2Fimage%2Fupload%2Fv1598363905%2FScreenshot_507_jhmmgq.png" alt="Final art"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! Now I want you to make your pixel art, and show it to the world!&lt;/p&gt;

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