<?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: JeffUbayi</title>
    <description>The latest articles on DEV Community by JeffUbayi (@carter).</description>
    <link>https://dev.to/carter</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%2F177678%2Fcc16862a-225e-43da-8f0f-584127ea8e14.jpg</url>
      <title>DEV Community: JeffUbayi</title>
      <link>https://dev.to/carter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/carter"/>
    <language>en</language>
    <item>
      <title>Study rules every Software Developer should know about</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Thu, 17 Dec 2020 07:52:38 +0000</pubDate>
      <link>https://dev.to/carter/study-rules-every-software-developer-should-know-about-57fa</link>
      <guid>https://dev.to/carter/study-rules-every-software-developer-should-know-about-57fa</guid>
      <description>&lt;p&gt;I recently changed jobs, and in this new company we are working with a different tech stack than I was used to.&lt;/p&gt;

&lt;p&gt;I had to quickly learn the new technologies and it was a challenge.&lt;/p&gt;

&lt;p&gt;Being a self-taught programmer, I already knew what I had to do and how to learn efficiently and quickly.&lt;/p&gt;

&lt;p&gt;In this post, I will go over ten rules that I follow whenever I have to learn something new.&lt;/p&gt;

&lt;h2&gt;
  
  
  1.Recall what you’ve just learned
&lt;/h2&gt;

&lt;p&gt;After going through a chapter or coding exercise, do something else and remember the main ideas of what you learned.&lt;br&gt;
Try recalling them when you are doing mundane activities like doing the dishes, going out to the store, or taking a shower.&lt;/p&gt;

&lt;p&gt;The ability to recall new things you learned will help you cement them in your mind much more easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.Actually write the code
&lt;/h2&gt;

&lt;p&gt;Imagine you are watching an awesome Laravel tutorial on YouTube.&lt;/p&gt;

&lt;p&gt;Now you’re already 2 hours in and can’t remember how the author got the database connection up and running.&lt;/p&gt;

&lt;p&gt;Now you have to go back to that specific section and re-watch it.&lt;/p&gt;

&lt;p&gt;What a waste of time!&lt;/p&gt;

&lt;p&gt;Write out the code as you go along with the tutorial you are watching or reading. If you cannot keep up with the pace, press pause, solve the issue or coding challenge, and then resume the video.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.Chunk the ideas and problems
&lt;/h2&gt;

&lt;p&gt;The idea of chunking is to understand and practice with an idea or solution to a problem to the point where you can recall it in a split second.&lt;/p&gt;

&lt;p&gt;Once you have learned that new programming concept, take some time to repeat it. Imagine a song about it and try to sing it in your mind over and over again.&lt;/p&gt;

&lt;p&gt;The information will turn into a chunk and you will be able to make a connection and pull it up whenever you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.Train your mind like you would train your body
&lt;/h2&gt;

&lt;p&gt;If you want to build muscle, you will need to train your body a little bit every day.&lt;br&gt;
But you wouldn’t want to train just one muscle group 7 days a week. It will not grow as much as you would like to. Muscles need time to grow. The tissues need time to regenerate and grow in mass.&lt;/p&gt;

&lt;p&gt;So one solution is to split your workout into muscle groups. On day one you train legs and abs, day two the chest, day three the back, and day four maybe the arms.&lt;/p&gt;

&lt;p&gt;That’s what you should do when you learn.&lt;/p&gt;

&lt;p&gt;Spread out your learning a little every day, just like a bodybuilder. The brain is like a muscle – it can handle only a limited amount of exercise on one subject at a time.&lt;/p&gt;

&lt;p&gt;Try to split your learning routine into something similar to muscle groups:&lt;br&gt;
– Database management day (SQL/NoSQL)&lt;br&gt;
– REST API day&lt;br&gt;
– Web Design day&lt;br&gt;
– Functional JavaScript day&lt;/p&gt;

&lt;h2&gt;
  
  
  5.Mix up different problem-solving techniques
&lt;/h2&gt;

&lt;p&gt;There is no one single way of solving a problem, that’s for sure. When you have a task and your way of solving the problem doesn’t seem to work very well, try a different approach.&lt;/p&gt;

&lt;p&gt;Mix things up and see if you can come up with multiple solutions.&lt;/p&gt;

&lt;p&gt;After every solution you have implemented, go over your errors and make sure you understand why you made them. Then, work on improving the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  6.Take breaks
&lt;/h2&gt;

&lt;p&gt;From my experience, it is common to be unable to solve problems or grasp concepts the first time you encounter them.&lt;/p&gt;

&lt;p&gt;Sometimes you get frustrated that you got stuck on a problem for so long and it seems you cannot figure a way out. This is the ideal moment when you need to take a break.&lt;/p&gt;

&lt;p&gt;Let your mind relax for a while. You’ll find out that sometimes the solution to your problems comes in your sleep, or when taking a bath.&lt;/p&gt;

&lt;p&gt;This is because a part of your mind is working in the background, figuring out things you might not be able to when you’re focused.&lt;/p&gt;

&lt;h2&gt;
  
  
  7.Explain Like I’m Five
&lt;/h2&gt;

&lt;p&gt;Have you ever heard of this concept &lt;code&gt;Explain Like I’m Five&lt;/code&gt;?&lt;br&gt;
There’s even a subreddit for it. And it’s a pretty neat mental exercise.&lt;/p&gt;

&lt;p&gt;Whenever you are struggling with a concept, ask yourself, how can you explain this so a 5-year-old could understand it?&lt;/p&gt;

&lt;p&gt;This exercise will make you think about how to simplify an answer using analogies.&lt;br&gt;
For example, how would you describe a database to a child?&lt;/p&gt;

&lt;p&gt;I would say that a database is like a bucket or a toy box.&lt;/p&gt;

&lt;p&gt;You organize your apartment or house by placing all the toys inside the box. Otherwise, the toys will be all over the place and you won’t be able to find them easily when you need them.&lt;/p&gt;

&lt;p&gt;The database solves all of these issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  8.Maintain your focus
&lt;/h2&gt;

&lt;p&gt;I bet you’ve heard this a thousand times before. This is a topic quite full of opinions and advice, some more unusual than others.&lt;/p&gt;

&lt;p&gt;When working on a problem, try to focus on that task so you’re as efficient as possible.&lt;br&gt;
It’s up to you to figure out how to focus on something and maintain it for a while.&lt;/p&gt;

&lt;p&gt;What I’ve found that works for me so far is to turn off all interrupting beeps, alarms, and notifications on my phone and computer.&lt;/p&gt;

&lt;p&gt;Besides this, I like listening to music that helps me focus. I found that I focus very well while listening to music that has no lyrics, like post-rock.&lt;/p&gt;

&lt;p&gt;I’ve created a special playlist that I listen to when I’m programming or stargazing.&lt;br&gt;
Check it out here.&lt;/p&gt;

&lt;h2&gt;
  
  
  9.Do the hardest things first
&lt;/h2&gt;

&lt;p&gt;Take advantage of a rested mind and do the hardest thing earliest in the day.&lt;/p&gt;

&lt;p&gt;There are some good reasons to do it this way.&lt;/p&gt;

&lt;p&gt;You will feel better during the day after getting rid of that unpleasant thing first.&lt;/p&gt;

&lt;p&gt;Harder things take more effort. By doing the hardest task earliest in the day, it will help make sure you’ve got enough time to complete it.&lt;/p&gt;

&lt;p&gt;Also, this makes it less likely that you’ll postpone the hardest task for the next day.&lt;/p&gt;

&lt;h2&gt;
  
  
  10.Motivate yourself
&lt;/h2&gt;

&lt;p&gt;Sometimes you feel like the work you are putting in is not getting you anywhere.&lt;/p&gt;

&lt;p&gt;This happens to everyone from time to time. You are not to blame, honestly.&lt;/p&gt;

&lt;p&gt;If you want to stay motivated, make yourself feel like you are making progress.&lt;/p&gt;

&lt;p&gt;No matter what’s happening in your life, always have one thing you’re making progress with, so you feel good about it and yourself.&lt;/p&gt;

&lt;p&gt;For example, if you want to learn JavaScript, make it your number one priority.&lt;/p&gt;

&lt;p&gt;Every day you should read a few pages of your favorite JavaScript book or work on personal and/or open-source projects that rely on JavaScript.&lt;/p&gt;

&lt;p&gt;If you want to read more tips on how to keep yourself motivated as a software developer, check out this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;p&gt;Learning software development is always a journey and not a destination.There is alot of tech stacks being used by different tech companies, thus you always have to keep up to date.&lt;br&gt;
I hope this post helped out in some cases where you have to learn to overcome obstacles in programming.&lt;br&gt;
How many of the above rules you already follow?&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>personaldevelopment</category>
    </item>
    <item>
      <title>React : Painting a Mental Model </title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Sat, 18 Jul 2020 07:12:15 +0000</pubDate>
      <link>https://dev.to/carter/react-painting-a-mental-model-1hd8</link>
      <guid>https://dev.to/carter/react-painting-a-mental-model-1hd8</guid>
      <description>&lt;p&gt;Whether you’ve been working with React for years or are just starting, having a useful mental model is, in my opinion, the fastest way to feel confident working with it.&lt;br&gt;
By having a good mental model you can intuitively understand complex problems and device solutions much faster than if you had to find a solution with a step-by-step process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5mMIboH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/c9f28303d7dad2744b40d64b0ab33358/9aabf/react-mental-model-illustration.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5mMIboH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/c9f28303d7dad2744b40d64b0ab33358/9aabf/react-mental-model-illustration.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer: This article is written by a beginner trying to comb through new concepts he just learned. Also available on my &lt;a href="https://jeffubayi.site/blog/react-mental-models"&gt;Blog&lt;/a&gt; where I explain the mental models that helped me solve problems and tame complexity. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  why Are Mental Models Important?
&lt;/h2&gt;

&lt;p&gt;When I started building websites,I had a hard time understanding how it all worked. Building blog sites with WordPress was easy, but I had no idea about hosting, servers, DNS, certificates, and much more.&lt;/p&gt;

&lt;p&gt;As I read articles and tried stuff out, I started to grasp the system, to get glimpses into how it all worked, until eventually it “clicked” and I felt comfortable working with it. My mind had built a mental model around this system that I could use to work with it.&lt;/p&gt;

&lt;p&gt;If someone had explained it by transferred their mental model to me, I would’ve understood it much faster. Here I’ll explain (and show) the mental models I use with React. It will help you understand React better and make you a better developer.&lt;/p&gt;
&lt;h2&gt;
  
  
  React Mental Models
&lt;/h2&gt;

&lt;p&gt;React helps us build complex, interactive UIs more easily than ever before. It also encourages us to write code in a certain way, guiding us to create apps that are simpler to navigate and understand.&lt;/p&gt;

&lt;p&gt;An abstract model inside a mind looking at the React logo&lt;br&gt;
React itself is a mental model with a simple idea at its core: encapsulate portions of your app that rely on similar logic and UI and React will make sure that portion is always up kept up to date.&lt;/p&gt;

&lt;p&gt;Whether you’ve been working with React for years or are just starting, having a clear mental model is the best way to feel confident working with it. So for me to transfer my mental models to you I’ll start from first-principles and build on top of them.&lt;/p&gt;
&lt;h2&gt;
  
  
  It’s Functions All The Way Down
&lt;/h2&gt;

&lt;p&gt;Let’s start by modeling the basic building blocks of JavaScript and React: functions.&lt;/p&gt;
&lt;h2&gt;
  
  
  A React component is just a function
&lt;/h2&gt;

&lt;p&gt;Components containing other components are functions calling other functions&lt;br&gt;
Props are the function’s arguments&lt;br&gt;
This is hidden away by JSX, the markup language React uses. Strip away JSX and React is a bunch of functions calling one another. JSX is in itself an applied mental model that makes using React simpler and more intuitive.&lt;/p&gt;

&lt;p&gt;Let’s look at each part individually.&lt;/p&gt;
&lt;h2&gt;
  
  
  A Component Is A Function That Returns JSX
&lt;/h2&gt;

&lt;p&gt;React is used with JSX—JavaScript XML—a way to write what seems as HTML with all of JavaScript’s power. JSX offers a great applied mental model for using nested functions in a way that feels intuitive.&lt;/p&gt;

&lt;p&gt;Let’s ignore class components and focus on the far more common functional components. A functional component is a function that behaves exactly like any other JavaScript function. React components always return JSX which is then executed and turned into HTML.&lt;/p&gt;

&lt;p&gt;This is what simple JSX looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Li&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;RickRoll&lt;/span&gt; &lt;span class="o"&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'wrapper'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Li&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Never give you up&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Which compiled into pure JavaScript by Babel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Li&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;RickRoll&lt;/span&gt; &lt;span class="o"&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="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&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="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wrapper&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nx"&gt;Li&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Never give you up&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="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;If you find this code difficult to follow you’re not alone, and you will understand why the React team decided to use JSX instead.&lt;/p&gt;

&lt;p&gt;Now, notice how each component is a function calling another function, and each new component is the third argument for the React.createElement function. Whenever you write a component, it’s useful to keep in mind that it’s a normal JavaScript function.&lt;/p&gt;

&lt;p&gt;An important feature of React is that a component can have many children but only one parent. I found this a confusing until I realized it’s the same logic HTML has, where each element must be inside other elements, and can have many children. You can notice this in the code above, where there’s only one parent div containing all the children.&lt;/p&gt;

&lt;h2&gt;
  
  
  Component’s Props Are The Same As A Function’s Arguments
&lt;/h2&gt;

&lt;p&gt;When using a function we can use arguments to share information with that function. For React components we call these arguments props (funny story, I didn’t realize props is short for properties for a long time).&lt;/p&gt;

&lt;p&gt;Under the hood, props behave exactly like function arguments, the differences are that we interact with them through the nicer interface of JSX, and that React gives extra functionality to props such as children.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating A Mental Model Around Functions
&lt;/h2&gt;

&lt;p&gt;Using this knowledge let’s craft a mental model to intuitively understand functions!&lt;/p&gt;

&lt;p&gt;When I think about a function I imagine it as a box, and that box will do something whenever it’s called. It could return a value or not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;sum&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&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="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;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;logSum&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="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;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;// 30&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since a component is a fancy function, that makes a component a box as well, with props as the ingredients the box needs to create the output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VDgrp6LB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/1078eb1563b832008167b49c2b8edb11/0e356/a-plus-b-box.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VDgrp6LB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/1078eb1563b832008167b49c2b8edb11/0e356/a-plus-b-box.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a component is executed it will run whatever logic it has, if any, and evaluate its JSX. Any tags will become HTML and any component will be executed, and the process is repeated until reaching the last component in the chain of children.&lt;/p&gt;

&lt;p&gt;Since a component can have many children but only one parent I imagine multiple components as a set of boxes, one inside another. Each box must be contained within a bigger box and can have many smaller boxes inside.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kBb9RJPd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/cf7892f6a3db2815d6c502fe74538e4a/1f85e/box-inside-box.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kBb9RJPd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/cf7892f6a3db2815d6c502fe74538e4a/1f85e/box-inside-box.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the mental model of a box representing a component is not complete without understanding how it can interact with other boxes.&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Think About Closures
&lt;/h2&gt;

&lt;p&gt;Closures are a core concept in JavaScript. They enable complex functionality in the language, they’re super important to understand to have a good mental model around React.&lt;/p&gt;

&lt;p&gt;They’re also one of the features newcomers struggle with the most, so instead of explaining the technicalities I’ll demonstrate the mental model I have around closures.&lt;/p&gt;

&lt;p&gt;The basic description of a closure is that it’s a function. I imagine it as a box that keeps what’s inside of it from spilling out, while allowing the things outside of it from entering, like a semi-permeable box. But spilling out where?&lt;/p&gt;

&lt;p&gt;While the closure itself is a box, any closure will be inside bigger boxes, with the outermost box being the Window object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wE7qk84s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/952aebfcba6f1850f93b3bf6d15392f3/0e356/closures_window.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wE7qk84s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/952aebfcba6f1850f93b3bf6d15392f3/0e356/closures_window.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A box describing a mental model of a javascript closure, showing Window, scripts and React apps&lt;br&gt;
The window object encapsulates everything else&lt;/p&gt;
&lt;h2&gt;
  
  
  But What Is A Closure?
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;closure&lt;/code&gt; is a feature of JavaScript functions. If you’re using a function, you’re using a closure.&lt;/p&gt;

&lt;p&gt;As I’ve mentioned, a function is a box and that makes a closure a box too. Considering that each function can contain many others inside of it, then the closure is the ability of a function to use the information outside of it, while keeping the information it has inside from “spilling out”, or being used by the outer function.&lt;/p&gt;

&lt;p&gt;Speaking in terms of my mental model: I imagine the functions as boxes within boxes, and each smaller box can see the information of the outer box, or parent, but the big box cannot see the smaller one’s information. That’s as simple and accurate an explanation of closures as I can make.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qkec18uF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/96f403cd585425c1057214447165bbbe/ffce4/data-flow.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qkec18uF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/96f403cd585425c1057214447165bbbe/ffce4/data-flow.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Closures are important because they can be exploited to create some powerful mechanics and React takes full advantage of this.&lt;/p&gt;
&lt;h2&gt;
  
  
  Closures In React
&lt;/h2&gt;

&lt;p&gt;Each React component is also a closure. Within components, you can only pass props down from parent to child and the parent cannot see what’s inside the child, this is an intended feature to make our app’s data flow simpler to trace. To find where data comes from, we usually need to go up the tree to find which parent is sending it down.&lt;/p&gt;

&lt;p&gt;A great example of closures in React is updating a parent’s state through a child component. You’ve probably done this without realizing you were messing around with closures.&lt;/p&gt;

&lt;p&gt;To start, we know the parent can’t access the child’s information directly, but the child can access the parent’s. So we send down that info from parent to child through props. In this case, the information takes the shape of a function that updates the parent’s state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Parent&lt;/span&gt; &lt;span class="o"&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChildButtons&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&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;ChildButtons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;Increase&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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;Decrease&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When an onClick happens in a button, that will execute the function received from props props.onClick, and update the value using props.count.&lt;/p&gt;

&lt;p&gt;The insight here lies in the way we’re updating a parent’s state through a child, in this case, the props.onClick function. The reason this works is that the function was declared within the Parent component’s scope, within its closure, so it will have access to the parent’s information. Once that function is called in a child, it still lives in the same closure.&lt;/p&gt;

&lt;p&gt;This can be hard to grasp, so the way I imagine it is as a “tunnel” between closures. Each has its own scope, but we can create a one-way communication tunnel that connects both.&lt;/p&gt;

&lt;p&gt;Once we understand how closures affect our components, we can take the next big step: React state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fitting React’s State Into Our Mental Model
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;React’s philosophy is simple: it handles when and how to render elements, and developers control what to render. State is our tool to decide that what.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When state changes, its component renders and therefore re-executes all the code within. We do this to show new, updated information to the user.&lt;/p&gt;

&lt;p&gt;In my mental model state is like a special property inside the box. It’s independent of everything else that happens within it. It will get a default value on the first render and always be up to date with the latest value.&lt;/p&gt;

&lt;p&gt;Each variable and function is created on every render, which means their values are also brand new. Even if a variable’s value never changes, it is recalculated and reassigned every time. That’s not the case with state, it only changes when there’s a request for it to change via a &lt;code&gt;set state&lt;/code&gt; event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RYU3zQ_m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/acd86ef0ea8a3fe610df603769e68ad9/8d009/state-in-box.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RYU3zQ_m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/acd86ef0ea8a3fe610df603769e68ad9/8d009/state-in-box.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;State follows a simple rule: Whenever it changes it will re-rendered the component and its children. Props follow the same logic, if a prop changes, the component will re-render, however, we can control state by modifying it, props are more static and usually change as a reaction to a state change.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Rendering Mental Model: Understanding React’s Magic
&lt;/h2&gt;

&lt;p&gt;I consider rendering to be React’s most confusing part because a lot of things happen during rendering that sometimes isn’t obvious by looking at the code. That’s why having a clear mental model helps.&lt;/p&gt;

&lt;p&gt;The way I imagine rendering with my imaginary boxes is two-fold: the first render brings the box into existence, that’s when the state is initialized. The second part is when it re-renders, that’s the box being recycled, most of it is brand new but some important elements of it remain namely state.&lt;/p&gt;

&lt;p&gt;On every render, everything inside a component is created, including variables and functions, that’s why we can have variables storing a calculation’s results, since they will be recalculated on every render. It’s also why functions are not reliable as values, due to their reference (the function’s value, per se) being different every render.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Thumbnail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;withIcon&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AmazingIcon&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;imgUrl&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above will give a different result depending on the props the component receives. The reason React must re-render on every prop change is that it wants to keep the user up to date with the latest information.&lt;/p&gt;

&lt;p&gt;However, the state doesn’t change on re-renders, its value is maintained. That’s why the box is “recycled” instead of created brand new every time. Internally, React is keeping track of each box and making sure its state is always consistent. That’s how React knows when to update a component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E0NhXNWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/78de62863da9bd4c40c588c294167031/ffce4/react-rendering-mental-model.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E0NhXNWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/78de62863da9bd4c40c588c294167031/ffce4/react-rendering-mental-model.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By imagining a box being recycled I can understand what’s going on inside of it. For simple components, it’s easy to grasp, but the more complex a component becomes, the more props it receives, the more state it maintains, the more useful a clear mental model becomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Complete React Mental Model: Putting It All Together.
&lt;/h2&gt;

&lt;p&gt;Now that I’ve explained all the different parts of the puzzle separately, let’s put it all together. Here’s the complete mental model I use for React components, directly translated from how I imagine them into words.&lt;/p&gt;

&lt;p&gt;I imagine a React component as a box that contains all of its information within its walls, including its children, which are more boxes.&lt;/p&gt;

&lt;p&gt;And like a box in the real world, it can have other boxes inside of it and these boxes can, in turn, contain more boxes. That way each box/component must have a single parent, and a parent can have many children.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fELgj3Ch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/d6c8afaef3597fd26d9174e070be1ce3/0e356/react-mental-model-basic.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fELgj3Ch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/d6c8afaef3597fd26d9174e070be1ce3/0e356/react-mental-model-basic.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The boxes are semi-permeable, meaning they never leak anything to the outside but can use information from the outside as if it belonged to them. I imagine like this to represent how closures work in JavaScript.&lt;/p&gt;

&lt;p&gt;In React the way to share information between components is called props, the same idea applies to function and then it’s called arguments, they both work in the same way but with a different syntax.&lt;/p&gt;

&lt;p&gt;Within components, information can only travel down from parents to children. In other words, children can access their parent’s data and state, but not the other way around, and the way we share that information is through props.&lt;/p&gt;

&lt;p&gt;I imagine this directional sharing of information as boxes within boxes. With the inner-most box being able to absorb the parent’s data.&lt;/p&gt;

&lt;p&gt;React Mental model of data sharing between components visualized as information flowing downward as Data is shared from parent to child.&lt;br&gt;
The box must first be created though, and this happens on render, where the default value is given to state and just like with functions, all the code within the component is executed. In my mental model, this is equivalent to the box being created.&lt;/p&gt;

&lt;p&gt;Subsequent renders, or re-renders, execute all the code in the component again, recalculating variables, recreating functions, and so on. Everything except for state is brand new on each render. State’s value is maintained across renders is updated only through a set method.&lt;/p&gt;

&lt;p&gt;In my mental model, I see re-rendering as recycling the box since most of it is recreated, but it’s still the same box due to React keeping track of the component’s state.&lt;/p&gt;

&lt;p&gt;When a box is recycled all the boxes within it, its children, are also recycled. This can happen because the component’s state was modified or a prop changed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lFQ-b8tG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/267768646d810a0032728d222c3f13a5/ffce4/react-rendering-mental-model-full.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lFQ-b8tG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://obedparla.com/static/267768646d810a0032728d222c3f13a5/ffce4/react-rendering-mental-model-full.webp" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that a state or prop changing means the information the user sees is outdated, and React always wants to keep the UI updated so it re-renders the component that must show the new data.&lt;/p&gt;

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

&lt;p&gt;By using these mental models I feel confident when working with React. They help me visualize what can be a maze of code into a comprehensive mental map. It also demystifies React and brings it to a level I’m much more comfortable with.&lt;/p&gt;

&lt;p&gt;React is not that complex once you start understanding the core principles behind it and create some ways to imagine how your code works.&lt;/p&gt;

&lt;p&gt;I hope this article was useful to you and it was as enjoyable to read as it was to write! I realized that I understand React intuitively and putting that understanding into words was challenging.&lt;/p&gt;

</description>
      <category>react</category>
      <category>newbie</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Rapid UI development with Tailwind CSS</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Mon, 15 Jun 2020 20:24:22 +0000</pubDate>
      <link>https://dev.to/carter/rapid-ui-development-with-tailwind-css-1e03</link>
      <guid>https://dev.to/carter/rapid-ui-development-with-tailwind-css-1e03</guid>
      <description>&lt;h2&gt;
  
  
  What is Tailwind css
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS is a utility-first CSS framework intended to ease building web applications with speed and less focus to writing custom CSS, without leaving the comfort zone of your HTML code, yet achieve awesome interfaces.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f7IDCALG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seeklogo.com/images/T/tailwind-css-logo-5AD4175897-seeklogo.com.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f7IDCALG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://seeklogo.com/images/T/tailwind-css-logo-5AD4175897-seeklogo.com.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, even though Tailwind is considered a framework it doesn't fit under the same philosophy as the others. Tailwind is primarily a utility 🛠 framework or rather a utility bundle.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Utility-class&lt;/code&gt;  as building complex components from a constrained set of primitive utilities.&lt;/p&gt;

&lt;p&gt;Other CSS frameworks like Bootstrap present you with diverse predefined components (such as modals, buttons, alerts, cards). But with Tailwind CSS, you get to make your own, or you’re forced to make your own depending on your project model. Another way to put it, you actually own the components, and you get to harness your customization power on any component of your choice. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nx1hSBnq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--gDacVBBY--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_66%252Cw_880/https://thepracticaldev.s3.amazonaws.com/i/tqpthh0cv88anxyg48m0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nx1hSBnq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--gDacVBBY--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_66%252Cw_880/https://thepracticaldev.s3.amazonaws.com/i/tqpthh0cv88anxyg48m0.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means that there is no more need to fight against the framework, and trying to figure out which classes need to be overridden in order to get results you initially aimed for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;To help you get started, I've included a  component example built with utility classes that might be helpful for inspiration on how to create UI interfaces.&lt;br&gt;
Here is  the source code is on my &lt;a href="https://codepen.io/jeffubayi/pen/QWjejaO"&gt;Codepen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mJ2n_nc0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/drrzwqvfh/image/upload/v1590781230/tailwind_zkfbbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mJ2n_nc0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/drrzwqvfh/image/upload/v1590781230/tailwind_zkfbbg.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"max-w-sm mx-auto bg-gray-300 shadow-lg rounded-lg overflow-hidden"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"sm:flex sm:items-center px-6 py-4"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"block mx-auto sm:mx-0 sm:flex-shrink-0 h-16 sm:h-24 rounded-full"&lt;/span&gt;&lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://res.cloudinary.com/drrzwqvfh/image/upload/v1590779925/profile-pic-7b90c94f567c1a6c63b5873983d557e4_tact1l.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"jeff"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"mt-4 sm:mt-0 sm:ml-4 text-center sm:text-left"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text-xl leading-tight text-white-100"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; Jeff Ubayi&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text-sm leading-tight text-gray-700"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; Software Developer&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"mt-4"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text-blue-600 hover:text-white hover:bg-blue-300 border border-blue-400 text-xs font-semibold rounded-full px-4 py-1 -normal"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; Hire me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have used;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://tailwindcss.com/docs/max-width"&gt;max-width&lt;/a&gt; and &lt;a href="https://tailwindcss.com/docs/margin"&gt;margin&lt;/a&gt; utilities (&lt;code&gt;max-w-sm&lt;/code&gt; and &lt;code&gt;mx-auto&lt;/code&gt;) to constrain the card width and center it horizontally&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://tailwindcss.com/docs/background-color"&gt;background color&lt;/a&gt;, &lt;a href="https://tailwindcss.com/docs/border-radius"&gt;border radius&lt;/a&gt;, and &lt;a href="https://tailwindcss.com/docs/box-shadow"&gt;box-shadow&lt;/a&gt; utilities (&lt;code&gt;bg-gray-300&lt;/code&gt;, &lt;code&gt;rounded-lg&lt;/code&gt;, and &lt;code&gt;shadow-lg&lt;/code&gt;) to style the card's appearance&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://tailwindcss.com/docs/width"&gt;width&lt;/a&gt; and &lt;a href="https://tailwindcss.com/docs/height"&gt;height&lt;/a&gt; utilities (&lt;code&gt;w-12&lt;/code&gt; and &lt;code&gt;h-16&lt;/code&gt;) to size the profile image&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://tailwindcss.com/docs/font-size"&gt;font size&lt;/a&gt;, &lt;a href="https://tailwindcss.com/docs/text-color"&gt;text color&lt;/a&gt;, and &lt;a href="https://tailwindcss.com/docs/line-height"&gt;line-height&lt;/a&gt; utilities (&lt;code&gt;text-xl&lt;/code&gt;, &lt;code&gt;text-gray-700&lt;/code&gt;, &lt;code&gt;leading-tight&lt;/code&gt;, etc.) to style the card text&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://tailwindcss.com/docs/margin"&gt;margin&lt;/a&gt; and &lt;a href="https://tailwindcss.com/docs/padding"&gt;padding&lt;/a&gt; utilities (&lt;code&gt;mt-4&lt;/code&gt; and &lt;code&gt;px-6&lt;/code&gt;) to position the card text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now I know what you're thinking,  &lt;em&gt;"this is an atrocity, what a horrible mess!"&lt;/em&gt;  and you're right, it's kind of ugly. In fact it's just about impossible to think this is a good idea the first time you see it —  &lt;strong&gt;you have to actually try it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But once you've actually built something this way, you'll quickly notice some really important benefits in terms of: &lt;br&gt;
  &lt;a href="https://tailwindcss.com/docs/responsive-design"&gt;Responsive design&lt;/a&gt;, using predefined &lt;a href="https://tailwindcss.com/docs/theme"&gt;design systems&lt;/a&gt;  and styling with &lt;a href="https://tailwindcss.com/docs/pseudo-class-variants"&gt;Pseudo-classes&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why use Tailwind
&lt;/h2&gt;
&lt;h4&gt;
  
  
  1. Component friendly
&lt;/h4&gt;

&lt;p&gt;Tailwind provides tools for extracting component classes from repeated utility patterns, making it easy to update multiple instances of a component from one place:&lt;/p&gt;
&lt;h4&gt;
  
  
  2. No naming conventions
&lt;/h4&gt;

&lt;p&gt;One of the most stressful parts of writing custom CSS is having to name classes. At every point, you’re pondering which class should be generic or specific. How do you organize them and ensure they’re cascaded? Tailwind CSS solves those problems seamlessly by providing utility-based classes that can be used all the time.&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Designed to be customized
&lt;/h4&gt;

&lt;p&gt;Tailwind is written in [PostCSS] and configured in Javascript making it easy to customize colors, border sizes, font weights, spacing utilities, breakpoints, shadows, and tons more.&lt;/p&gt;
&lt;h4&gt;
  
  
  4. Cache benefits
&lt;/h4&gt;

&lt;p&gt;When writing custom CSS, you always have to make changes to your CSS files when making changes in your designs. With Tailwind CSS, you need not worry a bit about that since you’re using the same classes over and over again within the markup&lt;/p&gt;
&lt;h4&gt;
  
  
  5. Responsive
&lt;/h4&gt;

&lt;p&gt;Tailwind uses an intuitive {screen}: prefix that makes it easy to notice responsive classes in your markup while keeping the original class name recognizable and intact.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sm&lt;/code&gt;: small screen&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;md&lt;/code&gt;: medium screen&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lg&lt;/code&gt;: large screen&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;xl&lt;/code&gt;: extra large&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Creating your first project using Tailwind playground
&lt;/h2&gt;

&lt;p&gt;Tailwindcss playground,is a simple starter project for playing around with Tailwind in a proper PostCSS environment.&lt;/p&gt;

&lt;p&gt;To get started:&lt;/p&gt;

&lt;p&gt;Clone the &lt;a href="https://github.com/tailwindcss/playground"&gt;repository&lt;/a&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/tailwindcss/playground.git tailwindcss-playground
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;cd tailwindcss-playground&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       Install the dependencies:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Using npm
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Using Yarn
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Start the development server:&lt;/p&gt;
&lt;h3&gt;
  
  
  Using npm
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      npm run serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Using Yarn
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       yarn run serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now you should be able to see the project running at &lt;code&gt;localhost:8080&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M6XH6Ulc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codesandbox.io/api/v1/sandboxes/sr5sh/screenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M6XH6Ulc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codesandbox.io/api/v1/sandboxes/sr5sh/screenshot.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open public/index.html in your editor and start configuring your project to your expectations!&lt;/p&gt;
&lt;h3&gt;
  
  
  Configure your Tailwindcss file
&lt;/h3&gt;

&lt;p&gt;You can easily generate  a config file using Tailwinds CLI utility.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`npx tailwind init`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;It generates a 'tailwind.config.js' file which looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;extend&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="na"&gt;variants&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;plugins&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;The theme section of your tailwind.config.js file is where you define your project's color palette, type scale, font stacks, breakpoints, border radius values, and more.&lt;/p&gt;

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

&lt;p&gt;I think the idea of utility first approach is the way forward. This gives flexibility to the engineers to build UI's how ever they choose while leveraging the power of the utility. The utility updating under the hood allows to better browser support.&lt;/p&gt;

&lt;p&gt;With Tailwind CSS, you get to create the components that suit what you want or what you are working on. These components can be created by harnessing the power of the utility-first prowess of Tailwind CSS. If you are tired of making use of Bootstrap and its likes, you’ll find Tailwind CSS a good fit for working on beautiful interfaces as you implement the designs you need using the utility classes it provides&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>css</category>
      <category>codenewbie</category>
      <category>preprocessor</category>
    </item>
    <item>
      <title>Different ways of structuring Arrays in Javascript</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Tue, 26 May 2020 08:20:08 +0000</pubDate>
      <link>https://dev.to/carter/different-ways-of-structuring-arrays-in-javascript-5dac</link>
      <guid>https://dev.to/carter/different-ways-of-structuring-arrays-in-javascript-5dac</guid>
      <description>&lt;p&gt;Arrays are indispensable data-structures in javascript and understanding how to effectively use them to solve problems is a crucial skill to master.&lt;/p&gt;

&lt;p&gt;We will be taking a look into some of the many ways to create Arrays in Javascript.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Table of Contents:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#basic-way"&gt;Basic way&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#with-array-constructor"&gt;With Array Constructor&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#spread-operator"&gt;Spread Operator&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#from-another-array"&gt;From another Array&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#from-array-like-objects"&gt;From Array-Like Objects&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#using-loops-like-map-and-reduce"&gt;Using Loops like Map and Reduce&lt;/a&gt;
• &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#array-map"&gt;Array Map&lt;/a&gt;
• &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#array-reduce"&gt;Array Reduce&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#new-array-of-length-and-fill-with-some-value"&gt;New Array of Length and Fill with some value&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#form-objects-using-object-keys-and-object-values"&gt;Form Objects using Object.keys and Object.values&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.jeffubayi.site/blog/array-data-structures/#array-concat-function"&gt;Array Concat Function&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;I'll be using the Avengers Comic flick just to make learning fun while creating an array of Superheros.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o04KiudS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.longislandpress.com/wp-content/uploads/2017/07/the-avengers-15-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o04KiudS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.longislandpress.com/wp-content/uploads/2017/07/the-avengers-15-1.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets "Assemble the Avengers".&lt;/p&gt;
&lt;h2&gt;
  
  
  What is an Array
&lt;/h2&gt;

&lt;p&gt;An array data structure or an array is an ordered list of values, or a collection of elements (values or variables) identified by an index or key. The most simple type of array data structure is a linear array.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic way
&lt;/h2&gt;

&lt;p&gt;At first, the basic way to create arrays is here as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Avengers&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;Ironman&lt;/span&gt;&lt;span class="dl"&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;Hulk&lt;/span&gt;&lt;span class="dl"&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;Thor&lt;/span&gt;&lt;span class="dl"&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;Cpt America&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;h2&gt;
  
  
  With Array Constructor
&lt;/h2&gt;

&lt;p&gt;Another way to create array is by using Array Constructor function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Avengers&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;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hulk&lt;/span&gt;&lt;span class="dl"&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;Thor&lt;/span&gt;&lt;span class="dl"&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;Ironman&lt;/span&gt;&lt;span class="dl"&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;Cpt America&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 can achieve same with new Array function  &lt;code&gt;of&lt;/code&gt;. Like in the following example for  &lt;code&gt;Array.of&lt;/code&gt;  , we create array of mixed values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Avengers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hulk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Thor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;undefined&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;Avengers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// 👆 (4) ["Hulk", null, "Thor", undefined]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Interesting thing to notice about the Constructor function is its handy override. The override is that if you pass only one argument and it is an integer, the Constructor function will create an empty array for you of that specified length.&lt;/p&gt;




&lt;h2&gt;
  
  
  Spread Operator
&lt;/h2&gt;

&lt;p&gt;It &lt;strong&gt;spreads&lt;/strong&gt; the items that are contained in an &lt;strong&gt;iterable&lt;/strong&gt; (an iterable is anything that can be looped over, like Arrays, Sets…) inside a &lt;strong&gt;receiver&lt;/strong&gt; (A receiver is something that receives the spread values)&lt;/p&gt;

&lt;p&gt;Like in the following example, we will add the new item and spread the old array to create a complete new Array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;moreAvengers&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;Cpt Marvel&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;Avengers&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h2&gt;
  
  
  From another Array
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Array.from&lt;/code&gt;  will allow you to create the Arrays from another array.&lt;/p&gt;

&lt;p&gt;The newly created array is completely new copyrights and is not gonna mutate any changes to the old array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Avengers&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;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hulk&lt;/span&gt;&lt;span class="dl"&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;Thor&lt;/span&gt;&lt;span class="dl"&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;Cpt America&lt;/span&gt;&lt;span class="dl"&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;Ironman&lt;/span&gt;&lt;span class="dl"&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;copyOfAvengers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Avengers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h2&gt;
  
  
  From Array-Like Objects
&lt;/h2&gt;

&lt;p&gt;Some Lists look like Arrays but are not arrays. And, at that time you might wanna convert it to Array to better operability and readability on the data structure.&lt;/p&gt;

&lt;p&gt;One of such list is NodeList which you receive as an output of  &lt;code&gt;document.querySelectorAll&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;divs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&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;divsArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;divs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here you can use the  &lt;code&gt;Array.from&lt;/code&gt;  function as well to create the array from the Array-like objects. Let’s see that in the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;divs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&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;divsArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;divs&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--U3VGEwli--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/time2hack/image/upload/q_auto:good%2Cf_auto/nodelist-to-array-time2hack.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U3VGEwli--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/time2hack/image/upload/q_auto:good%2Cf_auto/nodelist-to-array-time2hack.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Loops like Map and Reduce
&lt;/h2&gt;

&lt;p&gt;Event though map and reduce are used to loop over the Arrays. Their non-mutating nature allows us to create new Arrays in different ways.&lt;/p&gt;

&lt;h3&gt;
  
  
  Array Map
&lt;/h3&gt;

&lt;p&gt;Map function will loop over items and return a new array of mapped Items&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Avengers&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;Hulk&lt;/span&gt;&lt;span class="dl"&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;Thor&lt;/span&gt;&lt;span class="dl"&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;Ironman&lt;/span&gt;&lt;span class="dl"&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;Cpt Amrica&lt;/span&gt;&lt;span class="dl"&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;avengersEndgame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Avengers&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;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&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="s2"&gt; kills Thanos`&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;avengersEndgame&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// 👆 (4) ["Hulk kills Thanos", "Thor kills Thanos", "Ironman kills Thanos", "Cpt America kills Thanos"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Array Reduce
&lt;/h3&gt;

&lt;p&gt;Reduce will allow you to loop over the items and do any kind of operation related to the item. The outputs of those operations can be added to any kind of collection, and here, a new Array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;avengers&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;Ironman&lt;/span&gt;&lt;span class="dl"&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;Hulk&lt;/span&gt;&lt;span class="dl"&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;Thor&lt;/span&gt;&lt;span class="dl"&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;cpt America&lt;/span&gt;&lt;span class="dl"&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;avengersCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;avengers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;gang&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;avengers&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="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;gang&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;avengers&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;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;avengersCopy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cm"&gt;/* 👆 
    .    (4) [{…}, {…}, {…}, {…}]
    .    0: {avenger: "Hulk"}
    .    1: {avenger: "Thor"}
    .    2: {avenger: "Cpt America"}
    .    3: {avenger: "Ironman"}
    .    length: 4
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  New Array of Length and Fill with some value
&lt;/h2&gt;

&lt;p&gt;We can quickly create new Arrays of any finite length with Array constructor.&lt;/p&gt;

&lt;p&gt;All we have to do is to pass that indefinite length of the desired array as a number to the constructor.&lt;/p&gt;

&lt;p&gt;Like in the following example, we will create a new Array of length  &lt;code&gt;6&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Though creating an empty array is useless because you will not be able to use the Array functions until it has items in it.&lt;/p&gt;

&lt;p&gt;One quick way to do so is to use the  &lt;code&gt;.fill&lt;/code&gt;  method of the array and put an arbitrary value in each index of the Array.&lt;/p&gt;

&lt;p&gt;Once the array is Filled,  you can use the loops to enhance it more with the different values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;emojis&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;Array&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;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;😎&lt;/span&gt;&lt;span class="dl"&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;emojis&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// 👆 (6) ["😎", "😎", "😎", "😎", "😎", "😎"]&lt;/span&gt;

&lt;span class="c1"&gt;// Breakdown: &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&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;Array&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;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;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cm"&gt;/* 👆
    .    (6) [empty × 6]
    .    length: 6
*/&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;toFixed&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="p"&gt;);&lt;/span&gt;
&lt;span class="cm"&gt;/* 👆
    .    (6) ["0.80", "0.80", "0.80", "0.80", "0.80", "0.80"]
    .    0: "0.80"
    .    1: "0.80"
    .    2: "0.80"
    .    3: "0.80"
    .    4: "0.80"
    .    5: "0.80"
    .    length: 6
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Form Objects using Object.keys and Object.values
&lt;/h2&gt;

&lt;p&gt;You can create array of Keys or Values of any Object with functions  &lt;code&gt;Object.keys&lt;/code&gt;  and  &lt;code&gt;Object.values&lt;/code&gt;  respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;avengers&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Black Panther&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ironman&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cpt America&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Thor&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hulk&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cpt Marvel&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Antman&lt;/span&gt;&lt;span class="dl"&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--YHXeDDQU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/rfLMykA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YHXeDDQU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/rfLMykA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Array Concat Function
&lt;/h2&gt;

&lt;p&gt;You can use the Array Concat function to create new Arrays as well.&lt;/p&gt;

&lt;p&gt;If you use an empty array as the starting point, the output of  &lt;code&gt;[].concat&lt;/code&gt;  will be a new copy of concatenated Arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;Avenger&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;Hulk&lt;/span&gt;&lt;span class="dl"&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;moreAvengers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[].&lt;/span&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Avenger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Thor&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ironman&lt;/span&gt;&lt;span class="dl"&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;moreAvengers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// (3) ["Hulk", "Thor", "Ironman"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;As we have seen some different ways to create Arrays in JavaScript.&lt;/p&gt;

&lt;p&gt;Not all of these methods can be used in same ways and every methods has its perk for specific use cases.&lt;/p&gt;

</description>
      <category>arrays</category>
      <category>datastructures</category>
      <category>javascript</category>
      <category>destructure</category>
    </item>
    <item>
      <title>From Promise chains to Async/Await</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Thu, 14 May 2020 19:39:56 +0000</pubDate>
      <link>https://dev.to/carter/from-promise-chains-to-async-await-5f6h</link>
      <guid>https://dev.to/carter/from-promise-chains-to-async-await-5f6h</guid>
      <description>&lt;p&gt;When writing JavaScript, we often have to deal with tasks that rely on other tasks. Thus, we end up with many nested callback functions that are dependent on previous callback functions. This is often referred to as &lt;strong&gt;callback hell&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Luckily, we now got something called &lt;strong&gt;Promises&lt;/strong&gt; to help us out.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Promises🤞🤞
&lt;/h2&gt;

&lt;p&gt;A promise is a placeholder for a value that can either resolve or reject at some time in the future.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c4JBI6TC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--9A_mOYMP--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/duen4peq0bdr55cka5ya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c4JBI6TC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--9A_mOYMP--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/duen4peq0bdr55cka5ya.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s see an example of a promise in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;data&lt;/span&gt; &lt;span class="o"&gt;=&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="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;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="o"&gt;=&amp;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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&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;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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

     &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&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="nx"&gt;status&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What is Async/Await ♾⌛️
&lt;/h2&gt;

&lt;p&gt;Let's finally move on to Async/Await ! First things first: Async Await is not a total replacement for Promises. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Async/Await&lt;/strong&gt; is built on top of promises, and it allows us to write asynchronous code more comfortably. It is just a new way of writing asynchronous code, besides promises and callbacks. It makes it look more “synchronous” too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DkyO7FEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://hackernoon.com/hn-images/1%2AIkgyvsWnvaGmyjWAUPnHUA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DkyO7FEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://hackernoon.com/hn-images/1%2AIkgyvsWnvaGmyjWAUPnHUA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s see the same code re-written using  &lt;code&gt;Async/Await&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;url&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;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;response&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="k"&gt;if&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="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

     &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&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="nx"&gt;status&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;responseData&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;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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;responseData&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="p"&gt;{&lt;/span&gt;

     &lt;span class="c1"&gt;// Failed to fetch the data&lt;/span&gt;

     &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&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;Which one do you prefer? In my opinion, it is clearer to understand what happens in the code when using  &lt;code&gt;async/await&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is happening
&lt;/h3&gt;

&lt;p&gt;Notice  that we are using the keyword &lt;code&gt;async&lt;/code&gt; in the method header.  This implies that the function always returns a promise. The keyword &lt;code&gt;await&lt;/code&gt; only works if you specify the keyword &lt;code&gt;async&lt;/code&gt; in the method header.&lt;/p&gt;

&lt;p&gt;The keyword &lt;code&gt;await&lt;/code&gt; makes the code wait until the promise is settled/rejected, and once it is resolved/rejected, it returns the result/error. Until the promise is settled, the engine can perform other things like executing other scripts. &lt;/p&gt;

&lt;p&gt;In the example above, the code stops at  &lt;code&gt;const response = await fetch(url);&lt;/code&gt;  and continues only after the promise is resolved. That is, once the URL is “fetched”. The constant response gets assigned whatever that URL returns. After that, the code resumes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of using Async/Await?
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Error handling
&lt;/h4&gt;

&lt;p&gt;Error stacks and debugging can be done for synchronous code and asynchronous code in the same construct. As a result, it provides better error handling. If there is an error in resolving the promise, the control jumps to the catch block to handle the error. Have a look at the second code snippet from above.&lt;/p&gt;

&lt;p&gt;You can even wrap multiple promises in the same try block, and the code catches the errors from all promises, not only from one. It also tells you where the error occurred, in which promise.&lt;/p&gt;

&lt;h4&gt;
  
  
  Clean and concise
&lt;/h4&gt;

&lt;p&gt;It allows us to write clear and better code.&lt;br&gt;
This is an advantage which is not that obvious when having just a few lines of code. But once you start writing a lot of code, it helps a lot in conciseness.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conditions
&lt;/h4&gt;

&lt;p&gt;Using less conditional operators in your code.  The first code snippet using the classic promise is a simple one. Imagine that you have four or more if statements. It quickly gets out of hand.&lt;/p&gt;

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

&lt;p&gt;What should you remember from this article?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Adding &lt;code&gt;async&lt;/code&gt; to your method header, you always return a promise. Besides that, it allows you to use the &lt;code&gt;await&lt;/code&gt; keyword. Therefore you can wait until a promise is resolved.&lt;/li&gt;
&lt;li&gt;  Makes the code more explicit, easier to understand, and more concise.&lt;/li&gt;
&lt;li&gt;  Using the &lt;code&gt;await&lt;/code&gt; keyword, you block the code from executing until the promise is resolved or rejected.&lt;/li&gt;
&lt;li&gt;  When the &lt;code&gt;promise&lt;/code&gt; cannot settle, it generates an exception.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for the read 👨💻.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Design a RESTful API with Python and Flask</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Wed, 08 Apr 2020 07:04:15 +0000</pubDate>
      <link>https://dev.to/carter/design-a-restful-api-with-python-and-flask-3klk</link>
      <guid>https://dev.to/carter/design-a-restful-api-with-python-and-flask-3klk</guid>
      <description>&lt;p&gt;In recent years &lt;strong&gt;REST&lt;/strong&gt; (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs.&lt;/p&gt;

&lt;p&gt;In this article I'm going to show you how easy it is to create a RESTful web service using &lt;a href="https://www.python.org/"&gt;Python&lt;/a&gt; and the &lt;a href="https://flask.palletsprojects.com/en/1.1.x/"&gt;Flask&lt;/a&gt; microframework.&lt;/p&gt;

&lt;p&gt;Code available on my &lt;a href="https://github.com/ubeezy/flask-book-api"&gt;Repo&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is REST&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It’s an architectural style for designing standards between computers, making it easier for systems to communicate with each other. In simpler terms, REST is a set of rules developers follow when they create APIs.&lt;/p&gt;

&lt;p&gt;A system is called &lt;strong&gt;RESTful&lt;/strong&gt; when it adheres to these constraints.RESTful APIs almost always rely on HTTP. When we are working with APIs, a client will send an HTTP request, and the server will respond with the HTTP response.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To set up a Python server, you need to install Python, I would suggest any version above 3.7 as of the year 2019.&lt;/p&gt;

&lt;p&gt;Download the latest Python version from the &lt;a href="https://www.python.org/downloads/"&gt;python.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once installed, open up your terminal/cmd and install flask.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ pip install Flask&lt;/code&gt;&lt;br&gt;
// or&lt;br&gt;
&lt;code&gt;$ py -m pip install Flask&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once flask is installed, we’ll need to set up a virtual environment to run our application.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Setting up a Virtual Environment.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We’ll start by creating a folder and adding a &lt;code&gt;venv&lt;/code&gt; folder within.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir sandbox
$ cd sandbox
$ py -m venv venv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To activate the environment, navigate to &lt;code&gt;venv/bin/activate&lt;/code&gt;  on Linux. &lt;br&gt;
On windows, use cmd and navigate to &lt;code&gt;venv/Scripts/activate&lt;/code&gt;&lt;br&gt;
Navigate back to &lt;code&gt;sandbox&lt;/code&gt; which is root and create a file &lt;code&gt;app.py&lt;/code&gt; .&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Create a minimal Flask application.&lt;/strong&gt;
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
  return 'Server Works!'

@app.route('/greet')
def say_hello():
  return 'Hello world'

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Here, we import Flask class and create an instance of it. To create an instance, we’d have to give it a name and using &lt;code&gt;(__name__)&lt;/code&gt; ensures that it can be started as an application or imported as a module.&lt;/p&gt;

&lt;p&gt;We the use the &lt;code&gt;route()&lt;/code&gt; decorator to let our flask app know which&lt;br&gt;
URL should trigger the corresponding method. The function then simply returns a string message using different URLs in the example.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; It’s important to note that by default, @app.route has a GET method. 
 If we want to use any other HTTP verbs, we have to specify them by passing 
 them via the methods parameter as a list.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To run the appliaction, we have to complete a few things first. So, set the environment to development and tell your terminal the application to work with by exporting the &lt;code&gt;FLASK_APP&lt;/code&gt; environment variable in Linux.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ export FLASK_ENV=development&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ export FLASK_APP=app.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and windows.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ set FLASK_ENV=development&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ set FLASK_APP=app.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run using.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ flask run&lt;/code&gt;&lt;br&gt;
// or&lt;br&gt;
&lt;code&gt;$ py -m flask run&lt;/code&gt;&lt;br&gt;
&lt;code&gt;* Running on http://127.0.0.1:5000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By default, the port is &lt;code&gt;5000&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;You’ve successfully created your first Python server using Flask. It’s quite basic and returns string responses, let’s spice things up a little by learning some more things we can do.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Routing.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Routes are considered to be endpoints, you can create different routes for your endpoints that use different methods.&lt;/p&gt;

&lt;p&gt;We use the &lt;code&gt;route()&lt;/code&gt; decorator to bind a function to a URL. Here’s a number of routes with details in the comments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/')
def index():
 return 'Index Page'

@app.route('/hello')
def hello():
 return 'Hello, greetings from different endpoint'

#adding variables
@app.route('/user/&amp;lt;username&amp;gt;')
def show_user(username):
 #returns the username
 return 'Username: %s' % username

@app.route('/post/&amp;lt;int:post_id&amp;gt;')
def show_post(post_id):
 #returns the post, the post_id should be an int
 return str(post_id)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By default, a route only answers to &lt;code&gt;GET&lt;/code&gt; requests. You’ll have to import request from flask to identify the type of method used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, request
app = Flask(__name__)

@app.route('/login', methods=['GET','POST'])
def login():
  if request.method == 'POST':
    #check user details from db
    login_user()
  elif request.method == 'GET':
    #serve login page
    serve_login_page()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Rendering Templates.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When using express.js, Pug is the default template engine. Well, in Flask we use Jinja2.&lt;br&gt;
Flask configures Jinja2 automatically when installing, and to render templates all you would need is to import render_template from flask and variables you would want to pass to the template engine as keyword arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

@app.route('/user/&amp;lt;name&amp;gt;')
def hello(name=None):
 #name=None ensures the code runs even when no name is provided
 return render_template('user-profile.html', name=name)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can learn more about Jinja2 &lt;a href=""&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Accessing Request Data.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You might want to pass data via the more secure &lt;code&gt;POST&lt;/code&gt; method as opposed to exposing it via the URL. To access form data (transmitted via &lt;code&gt;POST&lt;/code&gt; or &lt;code&gt;PUT&lt;/code&gt; methods), you can use the form attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, request

app = Flask(__name__)

@app.route('/user', methods=['GET','POST'])
def get_user():
 username = request.form['username']
 password = request.form['password']
 #login(arg,arg) is a function that tries to log in and returns true or false
 status = login(username, password)
 return status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If the keys &lt;code&gt;username&lt;/code&gt; or &lt;code&gt;password&lt;/code&gt; does not exist, then a special &lt;code&gt;KeyError&lt;/code&gt; is raised. You can catch it like any other error but if you don’t do that, a HTTP 400 (Bad Request) error page is shown. To access parameters submitted in the URL ( &lt;code&gt;?key=value&lt;/code&gt; ) you can use the &lt;strong&gt;args&lt;/strong&gt; attribute.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;searchkeyword = request.args.get('key': '')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It’s recommended to catch KeyError when using URL parameters as some users can&lt;br&gt;
change the URL which may return a Bad Request error page.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;File Uploads.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Python is a very simple language, it gets even simpler using Flask to upload images, files or videos. Flask allows you to upload files from a form object, just make sure you set  &lt;code&gt;enctype="multipart/form-data"&lt;/code&gt;  attribute on your form.&lt;/p&gt;

&lt;p&gt;While uploaded files are temporalily stored in memory or at a temporary location in the file system, you can use the &lt;code&gt;save()&lt;/code&gt; method to store the file in the server file system.&lt;/p&gt;

&lt;p&gt;When you create a server, it’s not recommended you store files on the server, you should store files to a service like AWS Storage, Firebase (by Google), Azure (Microsoft),&lt;br&gt;
Dropbox and others and only keep the url to these files stored in a separate database as strings, maybe even in the server.&lt;br&gt;
However, here’s how you can save files on the server just incase you just want to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, request

app = Flask(__name__)

@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        static_file = request.files['the_file']
        # here you can send this static_file to a storage service
        # or save it permanently to the file system
        static_file.save('/var/www/uploads/profilephoto.png')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can access your file using the hostname of your server plus the file directory after saving to the file system.i.e&lt;/p&gt;

&lt;p&gt;&lt;a href="https://myapp.com/var/www/uploads/profilephoto.png"&gt;https://myapp.com/var/www/uploads/profilephoto.png&lt;/a&gt; &lt;/p&gt;




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

&lt;p&gt;It’s pretty easy to build APIs with Flask. You can respond with JSON by serializing the value into JSON and returning it.&lt;br&gt;
Use the json module that comes with python to serialize your data into JSON.&lt;br&gt;
You can connect to MongoDB and store values using the popular pymongo, or connect to any other database.&lt;br&gt;
SQLite3 comes by default in Python. It’s not recommended to use an SQLite database however as your application scales, it’s not powerful enough to handle a lot of data.&lt;/p&gt;

&lt;p&gt;If you’re interested more in learning how to connect to databases and store data or upload files to storage services you might want to follow me??. Hopefully, you can now set up your own custom REST APIs using Flask. &lt;/p&gt;

&lt;p&gt;Thanks for going through this article????..&lt;/p&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>rest</category>
      <category>restapi</category>
    </item>
    <item>
      <title>Regular Expressions(RegEx)in JavaScript</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Tue, 25 Feb 2020 08:39:56 +0000</pubDate>
      <link>https://dev.to/carter/regular-expressions-regex-in-javascript-4m9h</link>
      <guid>https://dev.to/carter/regular-expressions-regex-in-javascript-4m9h</guid>
      <description>&lt;p&gt;Regular expressions are a way to describe patterns in a string data. They form a small language of its own, which is a part of many programming languages like Javascript, Perl, Python, Php, and Java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regex&lt;/strong&gt; are written in a specific syntax and then usually applied on a larger string of text to see if the string meets the conditions defined in the regular expression. Regular expressions have the general syntax of a pattern and modifier, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/patterns/modifiers

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The pattern is the sequence of characters and the modifier is a single letter which changes the entire behavior of the regular expression.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a Regular Expression&lt;/strong&gt;&lt;br&gt;
There are two ways to create a regular expression in Javascript. It can be either created with RegExp constructor, or by using forward slashes ( / ) to enclose the pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regular expression using constructor:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; let regex = new RegExp('abc');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Regular expression using literal:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /abc/;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No matter which method you choose, the result is going to be a regex object. Both regex objects will have same methods and properties attached to them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Since forward slashes are used to enclose patterns in the above example, you have to escape the forward slash ( / ) with a backslash ( \ ) if you want to use it as a part of the regex&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RegEx Methods&lt;/strong&gt;&lt;br&gt;
We have two methods for testing regular expressions;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 .test()&lt;/strong&gt;&lt;br&gt;
The method is used to test whether a match  has been found or not.&lt;br&gt;
It returns a boolean true or false statement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /hello/;
let text =' hello devs';
let result = regex.test(text);
console.log(result);
//returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. exec()&lt;/strong&gt;&lt;br&gt;
This method returns an array containing all the matched groups.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let regex =/hello/;
let text = ' hello devs';
let results = regex.exec(text);
console.log(results);
// returns [ 'hello', index: 0, input: 'hello devs', groups: undefined ]

// 'hello' -&amp;gt; is the matched pattern.
// index: -&amp;gt; Is where the regular expression starts.
// input: -&amp;gt; Is the actual string passed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Simple regex patterns&lt;/strong&gt;&lt;br&gt;
It is the most basic pattern, which simply matches the literal text with the test string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /hello/;
console.log(regex.test('hello devs'));
// true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Special characters&lt;/strong&gt;&lt;br&gt;
Now, let’s tap into the full power of regular expressions when handling more complex cases.&lt;br&gt;
There are special symbols and characters that you have to memorize in order to fully understand the regular expressions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flags&lt;/strong&gt;&lt;br&gt;
Regular expressions have five optional flags or modifiers.Lets work with the two important ones.&lt;br&gt;
&lt;strong&gt;i&lt;/strong&gt;: This makes the searching case-insensitive&lt;br&gt;
&lt;strong&gt;g&lt;/strong&gt;: This makes the searching global which prevents it from stopping after the first match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regexGlobal = /abc/g;
console.log(regexGlobal.test('abc abc'));
// it will match all the occurence of 'abc', so it won't return 
// after first match.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regexInsensitive = /abc/i;
console.log(regexInsensitive.test('Abc'));
// returns true, because the case of string characters don't matter 
// in case-insensitive search.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Character groups:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Character set [xyz] —&lt;/strong&gt; A character set is a way to match different characters in a single position, it matches any single character in the string from characters present inside the brackets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /[bt]ear/;
console.log(regex.test('tear'));
// returns true
console.log(regex.test('bear'));
// return true
console.log(regex.test('fear'));
// return false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note — All the special characters except for caret (^) (Which has entirely different meaning inside the character set) lose their special meaning inside the character set.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ranges [a-z] —&lt;/strong&gt; Suppose we want to match all of the letters of an alphabet in a single position, we could write all the letters inside the brackets, but there is an easier way and that is ranges&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /[a-z]ear/;
console.log(regex.test('fear'));
// returns true
console.log(regex.test('tear'));
// returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Meta-characters —&lt;/strong&gt; Meta-characters are characters with a special meaning. There are many meta character but I am going to cover the most important ones here.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;\d&lt;/strong&gt;&lt;/em&gt; — Match any digit character ( same as [0-9] ).&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\w&lt;/strong&gt;&lt;/em&gt; — Match any word character. A word character is any letter, digit, and underscore. (Same as [a-zA-Z0–9_] ) i.e alphanumeric character.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\s&lt;/strong&gt;&lt;/em&gt; — Match a whitespace character (spaces, tabs etc).&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\t&lt;/strong&gt;&lt;/em&gt; — Match a tab character only.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\b&lt;/strong&gt;&lt;/em&gt; — Find a match at beginning or ending of a word. Also known as word boundary.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/em&gt; — (period) Matches any character except for newline.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\D&lt;/strong&gt;&lt;/em&gt; — Match any non digit character (same as [^0–9]).&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\W&lt;/strong&gt;&lt;/em&gt; — Match any non word character (Same as [^a-zA-Z0–9_] ).&lt;br&gt;
&lt;em&gt;&lt;strong&gt;\S&lt;/strong&gt;&lt;/em&gt; — Match a non whitespace character.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quantifiers: —&lt;/strong&gt; Quantifiers are symbols that have a special meaning in a regular expression.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+&lt;/strong&gt; — Matches the preceding expression 1 or more times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let  regex = /\d+/;
console.log(regex.test('8'));
// true
console.log(regex.test('88899'));
// true
console.log(regex.test('8888845'));
// true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;—Matches the preceding expression 0 or more times.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let  regex = /go*d/;
console.log(regex.test('gd'));
// true
console.log(regex.test('god'));
// true
console.log(regex.test('good'));
// true
console.log(regex.test('goood'));
// true

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;?&lt;/strong&gt; — Matches the preceding expression 0 or 1 time, that is preceding pattern is optional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /goo?d/;
console.log(regex.test('god'));
// true
console.log(regex.test('good'));
// true
console.log(regex.test('goood'));
// false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;^&lt;/strong&gt; — Matches the beginning of the string, the regular expression that follows it should be at the start of the test string. i.e the caret (^) matches the start of string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /^g/;
console.log(regex.test('good'));
// true
console.log(regex.test('bad'));
// false
console.log(regex.test('tag'));
//
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;$&lt;/strong&gt; — Matches the end of the string, that is the regular expression that precedes it should be at the end of the test string. The dollar ($) sign matches the end of the string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /.com$/;
console.log(regex.test('test@testmail.com'));
// true
console.log(regex.test('test@testmail'));
// false

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;{N}&lt;/strong&gt; — Matches exactly N occurrences of the preceding regular expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /go{2}d/;
console.log(regex.test('good'));
// true
console.log(regex.test('god'));
// false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;{N,}&lt;/strong&gt; — Matches at least N occurrences of the preceding regular expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /go{2,}d/;
console.log(regex.test('good'));
// true
console.log(regex.test('goood'));
// true
console.log(regex.test('gooood'));
// true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;{N,M}&lt;/strong&gt; — Matches at least N occurrences and at most M occurrences of the preceding regular expression (where M &amp;gt; N).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /go{1,2}d/;
console.log(regex.test('god'));
// true
console.log(regex.test('good'));
// true
console.log(regex.test('goood'));
// false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Alternation X|Y&lt;/strong&gt; — Matches either X or Y. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let regex = /(green|red) apple/;
console.log(regex.test('green apple'));
// true
console.log(regex.test('red apple'));
// true
console.log(regex.test('blue apple'));
// false

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note — If you want to use any special character as a part of the expression, say for example you want to match literal + or ., then you have to escape them with backslash ( \ ).For example:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /a+b/;  // This won't work
let regex = /a\+b/; // This will work
console.log(regex.test('a+b')); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Practicing Regex:&lt;/strong&gt;&lt;br&gt;
Let’s practice some of the concepts that we have learned above.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Match any 10 digit number :&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /^\d{10}$/;
console.log(regex.test('9995484545'));
// true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s break that down and see what’s going on up there.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If we want to enforce that the match must span the whole string, we can add the quantifiers &lt;strong&gt;^&lt;/strong&gt; and &lt;strong&gt;$&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The caret &lt;strong&gt;^&lt;/strong&gt; matches the start of the input string, whereas the dollar sign &lt;strong&gt;$&lt;/strong&gt; matches the end. So it would not match if string contain more than 10 digits.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;\d&lt;/strong&gt; matches any digit character.
{10} matches the previous expression, in this case &lt;strong&gt;\d&lt;/strong&gt; exactly 10 times. So if the test string contains less than or more than 10 digits, the result will be false.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Match a date with following format DD-MM-YYYY or DD-MM-YY:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let regex = /^(\d{1,2}-){2}\d{2}(\d{2})?$/;
console.log(regex.test('01-01-1990'));
// true
console.log(regex.test('01-01-90'));
// true
console.log(regex.test('01-01-190'));
// false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s break that down and see what’s going on up there.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Again, we have wrapped the entire regular expression inside &lt;strong&gt;^&lt;/strong&gt; and &lt;strong&gt;$&lt;/strong&gt;, so that the match spans entire string.
( start of first subexpression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;\d{1,2}&lt;/strong&gt; matches at least 1 digit and at most 2 digits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-&lt;/strong&gt; matches the literal hyphen character.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;)&lt;/strong&gt; end of first subexpression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;{2}&lt;/strong&gt; match the first subexpression exactly two times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;\d{2}&lt;/strong&gt; matches exactly two digits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;(\d{2})?&lt;/strong&gt; matches exactly two digits. But it’s optional, so either year contains 2 digits or 4 digits.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Regular expression can be fairly complex at times, but having a proper understanding of the above concepts will help you understand more complex regex patterns easily. You can learn more about regex &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"&gt;here&lt;/a&gt; and practice it &lt;a href="http://www.hackerrank.com/domains/regex"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>regex</category>
      <category>javascript</category>
      <category>fundamentals</category>
    </item>
    <item>
      <title>Working with Django Rest Framework(DRF).</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Tue, 14 Jan 2020 14:20:33 +0000</pubDate>
      <link>https://dev.to/carter/working-with-django-rest-framework-drf-3adp</link>
      <guid>https://dev.to/carter/working-with-django-rest-framework-drf-3adp</guid>
      <description>&lt;p&gt;The first step is to install Django Rest-Framework and then create a new apis app.&lt;br&gt;
The source code is available on my &lt;a href="https://github.com/J3ffu633zy/ToDo"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All of our API information will be routed through here. Even if we had multiple apps in our project, we’d still only need a single apis app to control what the API does.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      (todo) $ pipenv install djangorestframework==3.10.3
      (todo) $ python manage.py startapp apis
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Add both the apis app and rest-framework to our installed apps.&lt;br&gt;
We also add Permissions so that only logged in users could access the API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#todo_project/settings.py

INSTALLED_APPS = [
    ...
    'rest_framework',
    'apis.apps.ApisConfig',
    'todos.apps.TodosConfig',
]

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
    ]

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



&lt;p&gt;As tradition,A Django app needs a dedicated url, view, and template to translate information from that database onto a webpage.While in DRF,we just need url,view and serializer.&lt;/p&gt;

&lt;p&gt;The url controls the access to the API endpoints,views controls the logic of the data being sent and serializers does the magic of converting our information into a suitable format(JSON,XML).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A normal webpage requires HTML, CSS, and JavaScript (usually). But our API is only sending data in the JSON format. No HTML. No CSS. Just data. The serializer translates our Django models into JSON and then the client app translates JSON into a full-blown webpage. The reverse, deserialization, also occurs when our API accepts a user input–for example submitting a new todo–which is translated from HTML into JSON then converted into our Django model.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inside our apis app we create a serializers.py and import our desired model by specifying which fields we want exposed.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      (todo) $ touch apis/serializers.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# apis/serializers.py

from rest_framework import serializers
from todos import models


class TodoSerializer(serializers.ModelSerializer):
    class Meta:
        fields = (
            'id',
            'title',
            'description',
        )
        model = models.Todo

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



&lt;p&gt;Next up is our view.DRF comes with several generic views that provides minimal functionality with a less code on our part.&lt;br&gt;
We create a ListView and a DetailView of our todo items and specify the models and serializers for each view.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# apis/views.py

from rest_framework import generics

from todos import models
from .serializers import TodoSerializer

class ListTodo(generics.ListCreateAPIView):
    queryset = models.Todo.objects.all()
    serializer_class = TodoSerializer


class DetailTodo(generics.RetrieveUpdateDestroyAPIView):
    queryset = models.Todo.objects.all()
    serializer_class = TodoSerializer

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



&lt;p&gt;All that's left is to update our API Urls both in the project level and app level.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# todo_project/urls.py

from django.contrib import admin
from django.urls import include, path


urlpatterns = [
    path('admin/', admin.site.urls),
    path('apis/v1/', include('apis.urls')),
]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The list of all todos will be at apis/v1/. Individual todo items will be at their pk which is automatically set by Django for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# apis/urls.py

from django.urls import path

from .views import ListTodo, DetailTodo

urlpatterns = [
    path('', ListTodo.as_view()),
    path('&amp;lt;int:pk&amp;gt;/', DetailTodo.as_view()),
]

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



&lt;p&gt;We now have an API of our To do project.Start the local server.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    (todo) $ python manage.py runserver&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Testing with the web browser&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;DRF comes with a very nice graphical user interface for our API.The listView for all items is at &lt;a href="http://127.0.0.1:8000/apis/v1/"&gt;http://127.0.0.1:8000/apis/v1/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J5v2CBMt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://wsvincent.com/assets/images/drf-todo/list.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J5v2CBMt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://wsvincent.com/assets/images/drf-todo/list.png" alt="https://wsvincent.com/assets/images/drf-todo/list.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pnWeKIBl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://wsvincent.com/assets/images/drf-todo/detail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pnWeKIBl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://wsvincent.com/assets/images/drf-todo/detail.png" alt="https://wsvincent.com/assets/images/drf-todo/detail.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can even use the forms on the bottom of each page to create, retrieve, destroy, and update new todo items.When your APIs become even more complex many developers like to use &lt;a href="https://www.getpostman.com/"&gt;Postman&lt;/a&gt; to explore and test an API.&lt;/p&gt;

&lt;p&gt;Voila,we have a working, albeit basic implementation of a Todo API.&lt;/p&gt;

&lt;p&gt;For &lt;a href="https://dev.to/carter/create-a-simple-api-using-django-rest-framework-in-python-4i77"&gt;Part 1 of this blog&lt;/a&gt;. Thanks for the read.&lt;/p&gt;

</description>
      <category>djangorestframework</category>
      <category>python</category>
      <category>api</category>
      <category>rest</category>
    </item>
    <item>
      <title>Create a simple API using Django Rest Framework in Python</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Sun, 05 Jan 2020 08:45:15 +0000</pubDate>
      <link>https://dev.to/carter/create-a-simple-api-using-django-rest-framework-in-python-4i77</link>
      <guid>https://dev.to/carter/create-a-simple-api-using-django-rest-framework-in-python-4i77</guid>
      <description>&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Django Rest Framework&lt;/strong&gt; is a powerful library that sits on top of existing Django projects to add robust web APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REST&lt;/strong&gt; is an "architectural style' that basically exploits the existing technology and protocols of the web.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API&lt;/strong&gt; a set of rules and mechanisms by which one application or component interacts with the others.&lt;/p&gt;

&lt;p&gt;In this tutorial we’ll create a basic Django &lt;strong&gt;ToDo app&lt;/strong&gt; and then convert it into a web API using serializers, viewsets, and routers.&lt;/p&gt;

&lt;p&gt;Complete source code is available on &lt;a href="https://github.com/J3ffu633zy/ToDo"&gt;Github&lt;/a&gt;  .&lt;/p&gt;

&lt;h2&gt;
  
  
  1.Initial setup
&lt;/h2&gt;

&lt;p&gt;Will commence by executing the following in the command line;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ cd ~/Destkop
    $ mkdir todo &amp;amp;&amp;amp; cd todo
    $ pipenv install django==2.2.5
    $ pipenv shell
    (todo) $ django-admin startproject todo_project .
    (todo) $ python manage.py startapp todos
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We've used pipenv to install django and started both a django project (todo_project) and an app(todos).&lt;br&gt;
Now we need to update our app in the settings file.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       # todo_project/settings.py
       INSTALLED_APPS = [
              ...
       'todos.apps.TodosConfig',
        ]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Perform our first migration to set up the initial database at this point.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       (todo) $ python manage.py migrate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  2.Models
&lt;/h3&gt;

&lt;p&gt;We create a basic model for our Todo app database.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       # todos/models.py
       from django.db import models

      class Todo(models.Model):
          title = models.CharField(max_length=200)
          description = models.TextField()

         def __str__(self):
            return self.title
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Makemigrations for the project database to the Server.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      (todo) $ python manage.py makemigrations todos
      (todo) $ python manage.py migrate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Register the app on the admin file to showcase the models on the server dashboard.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     # todos/admin.py
     from django.contrib import admin

     from .models import Todo

     admin.site.register(Todo)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In a normal Django app at this point we would need to add urls, views, and templates to display our content. But since our end goal is an API that will transmit the data over the internet, we don’t actually need anything beyond our models.py file!&lt;/p&gt;

&lt;p&gt;Lets create a superuser to act as an ADMIN and then power off the django project to the server.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     (todo) $ python manage.py createsuperuser
     (todo) $ python manage.py runserver
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Navigate to &lt;a href="http://127.0.0.1:8000/admin"&gt;http://127.0.0.1:8000/admin&lt;/a&gt; and log in with your new superuser account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xj3O8Bvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/83X7wuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xj3O8Bvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/83X7wuh.png" alt="Django Admin Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Todos and add your entries.I added the following;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      1st todo = Learn DRF
      2nd item = Learn Python too
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M9HYsn-1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/UWNKTd4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M9HYsn-1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/UWNKTd4.png" alt="Entries for Todo app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it’s time to use Django Rest Framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 2&lt;/strong&gt;.....&lt;/p&gt;

</description>
      <category>django</category>
      <category>djangorestframework</category>
      <category>rest</category>
      <category>api</category>
    </item>
    <item>
      <title>How to Setup Virtual Environment Using Pipenv</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Sat, 28 Dec 2019 08:34:33 +0000</pubDate>
      <link>https://dev.to/carter/how-to-setup-virtual-environment-using-pipenv-2m89</link>
      <guid>https://dev.to/carter/how-to-setup-virtual-environment-using-pipenv-2m89</guid>
      <description>&lt;p&gt;Virtual Environments using PipEnv&lt;/p&gt;

&lt;p&gt;PipEnv is a new way to create Virtual Environments in Python that allows for &lt;br&gt;
  Environment Agnostic dependency installation.&lt;/p&gt;

&lt;p&gt;It makes use of;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Pip(Python package manager)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Virtualenv(used for creating isolated Python environments to easily use different packages in different projects)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pipfile(records the package versions used in a given project so you can &lt;br&gt;
         easily install them on any other system you want. Also considered as &lt;br&gt;
         the replacement of Python requirements files)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Installing PipEnv&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  pip install --user pipenv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Next, we are going to set up the requirements.txt file to make sure you have &lt;br&gt;
  all the necessary dependencies for the rest of the book.&lt;/p&gt;

&lt;p&gt;Versions – Requirements.txt File&lt;/p&gt;

&lt;p&gt;The versions that you will need to follow this tutorial is provided for you by &lt;br&gt;
the following requirements.txt file.&lt;/p&gt;

&lt;p&gt;The instructions that you need to follow are also provided and should work on any Operating System. Here is the requirements.txt file that we are going to use:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;           Django==2.2
           djangorestframework==3.9.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Copy and Paste the above in a file labeled requirements.txt in the root directory of your app. Make sure you are inside of that directory.Then, run the following command:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       pipenv install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Using Pip inside your virtual environment&lt;/p&gt;

&lt;p&gt;An alternative to the requirements.txt file above is to use pip inside your &lt;br&gt;
  Virtual Environment.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      pipenv shell
      pipenv install django
      pipenv install djangorestframework
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Once it’s finished, you should have a PipFile file and a PipFile.lock file.&lt;/p&gt;

&lt;p&gt;Congratulations! You installed PipEnv and you have an environment that is ready to go for the development for the rest of the book.&lt;/p&gt;

&lt;p&gt;Everytime you sit at the computer you should do this…&lt;/p&gt;

&lt;p&gt;When you’re ready to sit down and work on your project, you should do the &lt;br&gt;
  following:&lt;/p&gt;

&lt;p&gt;Open up your terminal and go to the directory with the PipFile file and a &lt;br&gt;
  PipFile.lock file. Then, type:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      pipenv shell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Your shell should be changed – it should be noticeably different. Mine &lt;br&gt;
  looks like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     (token_auth_app) bash-3.2$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Yours should be similar, although what is inside of the parentheses might be &lt;br&gt;
  different.&lt;/p&gt;

&lt;p&gt;Everytime you are done working on your app you should do this…&lt;/p&gt;

&lt;p&gt;When you’re done working, you should deactivate the Virtual Envionment by &lt;br&gt;
  running the following two commands:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        deactivate
        exit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This will kick you out of the Virtual Environment so you don’t mess up the virtual environment for later.&lt;/p&gt;

&lt;p&gt;Other commands related to Pipenv shell include:&lt;/p&gt;

&lt;p&gt;Checks for security vulnerabilities;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       pipenv check
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Will run a command from the virtualenv;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       pipenv run *
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Shows you a graph of your installed dependencies;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       pipenv graph
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Check local packages&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      pipenv lock -r
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Install a dev package&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      pipenv install nose --dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Ignore pipfile&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     pipenv install --ignore-pipfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Set lockfile - before deployment&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     pipenv lock
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Synchronize to use an existing pipenv&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     pipenv sync
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So basically with one short pipenv command you can install a package in a virtual environment and record it in pipfile and pipefile.lock files. Think of pipenv as next gen package management tool that should save you time and also provide you with new shiny utilities.&lt;/p&gt;

&lt;p&gt;Thanks for the read.&lt;/p&gt;

</description>
      <category>pipenv</category>
      <category>python</category>
      <category>packages</category>
    </item>
    <item>
      <title>Deploy your website with Github Pages</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Tue, 17 Dec 2019 09:52:48 +0000</pubDate>
      <link>https://dev.to/carter/deploy-your-website-with-github-pages-e26</link>
      <guid>https://dev.to/carter/deploy-your-website-with-github-pages-e26</guid>
      <description>&lt;p&gt;All of us devs, at one point or other, would have wanted to have a personal website of our own, just  to showcase our online presence or for fun. So here, I worked on my landing site and deployed it to github.&lt;/p&gt;

&lt;p&gt;Usually creating a personal website would involve buying/registering a domain name, finding a free/paid hosting service, developing your site and uploading it to the hosting provider.&lt;/p&gt;

&lt;p&gt;But with GitHub Pages, publishing your static site is as easy as drinking a coffee.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  You need a GitHub account (you obviously have one already)

  Create a new repo with the name {username}.github.io

  Clone the repo and create an index.html file

  Add some content and git push

  Voila! Your site should be live at https://{username}.github.io in seconds.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Github Pages&lt;/p&gt;

&lt;p&gt;To view the link to your published repo on gh-pages,it is located at the &lt;br&gt;
 settings on your github repo.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Scroll down to github pages.

 Click the link "your site is published at: https//{username}.github.io/"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Developer Landing Page&lt;/p&gt;

&lt;p&gt;I wanted a Dev Landing Page to showcase everything I do online. And I wanted it to be minimal and right to the point. So I sat down and created this Dev Landing Page,with some HTML,CSS and JavaScript.&lt;/p&gt;

&lt;p&gt;Here's my Dev Landing Page &lt;a href="https://j3ffu633zy.github.io/"&gt;https://j3ffu633zy.github.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading,Happy Coding.&lt;/p&gt;

</description>
      <category>github</category>
      <category>tutorial</category>
      <category>website</category>
      <category>git</category>
    </item>
    <item>
      <title>Git - Useful Cheat Sheet</title>
      <dc:creator>JeffUbayi</dc:creator>
      <pubDate>Fri, 13 Dec 2019 07:34:31 +0000</pubDate>
      <link>https://dev.to/carter/git-useful-cheat-sheet-16p</link>
      <guid>https://dev.to/carter/git-useful-cheat-sheet-16p</guid>
      <description>&lt;p&gt;What is git?&lt;br&gt;
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.&lt;/p&gt;

&lt;p&gt;With Git it’s easy to undo changes back and forth with a precise explanation of the changes that are made. It has the ability of:&lt;/p&gt;

&lt;p&gt;-Keeping a track of the changes i.e. different versions of the same file.&lt;br&gt;
-It also keeps a record of all the files present in a project.&lt;br&gt;
-Comparing and analyzing different codes with a detailed explanation.&lt;/p&gt;

&lt;p&gt;Basic Commands:&lt;/p&gt;

&lt;p&gt;Initialize local git repository&lt;/p&gt;

&lt;div class="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;check files to commits and branch name&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;add files to staging area.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add FileName.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;add all modified and new files to staging area&lt;/p&gt;

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

&lt;p&gt;add all files of directory to staging area&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git add folder/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Commit changes to local repository&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git commit -m “Message to commit”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;history of commits&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git log –
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Get help for any command&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git help
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;set global user name&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git config –global user.name “Name”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Show un-staged differences since last commit&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git diff
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;View staged differences&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git diff –staged
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Un-stage files and HEAD Refers to last commit&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git reset HEAD FileName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Blow away all changes since last commit&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git checkout – FileName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Skip stagging to commit and Add changes from all tracked files. this Doesn’t add new (untracked) files&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git commit -a -m “Modify readme”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Reset into staging and Move to commit before ‘HEAD’&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git reset –soft HEAD^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Add to the last commit with new commit message&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git commit –amend -m “New Message”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Undo last commit and all changes&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git reset –hard HEAD^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Undo last 2 commits and all changes&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git reset –hard HEAD^^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Adding a remote&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git remote add origin git url
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;show remote repositories&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git remote -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Remove remote&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git remote rm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Clone remote repository&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git clone git url
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Create branch&lt;/p&gt;

&lt;div class="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;create and checkout branch&lt;/p&gt;

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

&lt;p&gt;list available branches&lt;/p&gt;

&lt;div class="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;list remote available branches&lt;/p&gt;

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

&lt;p&gt;Switching between branches&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git checkout
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;merge 2 branches&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git merge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Delete branch&lt;/p&gt;

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

&lt;p&gt;Force delete branch&lt;/p&gt;

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

&lt;p&gt;get remote changes&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git pull
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;get the remote changes to local remote branch&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git fetch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;merge local remote branch changes to local master branch&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git merge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;shows branches alignments&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git remote show origin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;remove remote branch&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git push origin :
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To clean up deleted remote branches&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git remote prune origin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;List all tags&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git tag
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Create tag&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git tag -a -m “Tag message”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Push new tags to remote&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git push –tags
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Revert to existing tag.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git checkout
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Determine who made changes to a file.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ git blame
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Remove all unexpected files in your project (not committed).&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ git clean -dfx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To push to remotes&lt;/p&gt;

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

&lt;p&gt;Modify amend the previous commit&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ git commit –amend
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Save uncommitted changes for later use&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ git stash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That's all, Hope you git it now.&lt;/p&gt;

&lt;p&gt;For more useful developer posts,visit &lt;a href="//ubeezy.netlify.com"&gt;my blog&lt;/a&gt;.&lt;/p&gt;

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