<?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: Thomas(Tripp) White </title>
    <description>The latest articles on DEV Community by Thomas(Tripp) White  (@turpp).</description>
    <link>https://dev.to/turpp</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%2F487274%2F6a149e73-41fe-4d9c-a834-fdaabbb7daee.png</url>
      <title>DEV Community: Thomas(Tripp) White </title>
      <link>https://dev.to/turpp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/turpp"/>
    <language>en</language>
    <item>
      <title>Destructuring in Javascript</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 31 Oct 2021 20:54:46 +0000</pubDate>
      <link>https://dev.to/turpp/destructuring-in-javascript-43jj</link>
      <guid>https://dev.to/turpp/destructuring-in-javascript-43jj</guid>
      <description>&lt;p&gt;Where would we be without ES6? Destructuring is one of the many things that were introduced. It’s easy forget about it with all the other major features added, but its a nice quick and short way to clean up your code. In this article I will explain what Destructuring is and how to implement it.&lt;/p&gt;

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

&lt;p&gt;Destructuring in Javascript gives us the ability to extract values from objects. No longer are the days where you have to create multiple variables and call every element of an array or every key on an object to assign them. Destructuring gives us a streamlined way to exact the values we want all in one line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//pre ES6&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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;Ada&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;Taz&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dog1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dog2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="nx"&gt;dog1&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'Ada'&lt;/span&gt;
&lt;span class="nx"&gt;dog2&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'Taz'&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;boyDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;girlDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;boyDog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;boyDog&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;girlDog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;girlDog&lt;/span&gt;

&lt;span class="nx"&gt;boyDog&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'Taz'&lt;/span&gt;
&lt;span class="nx"&gt;girlDog&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'Ada'&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The above is an example of assigning variables from an array and object. For the Array, we have to use the element index to extract the value. For the object, we have to use the key to extract the value. We also have to use the variable keyword for each variable we are creating. While this is simple to follow and easy to write it takes up a lot of space. I am only doing this with two values inside my objects. Imagine how tiring and boring it would get with larger datasets!&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Setting up the Destructuring Assignment is very simple. It looks a little strange at first glance. Lets break it down.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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;Ada&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;Taz&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;dog1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dog2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dogs&lt;/span&gt;

&lt;span class="nx"&gt;dog1&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'Ada'&lt;/span&gt;
&lt;span class="nx"&gt;dog2&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'Taz'&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;boyDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;girlDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;boyDog&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;girlDog&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt;

&lt;span class="nx"&gt;boyDog&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; "Taz"&lt;/span&gt;
&lt;span class="nx"&gt;girlDog&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; "Ada"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Whoah, thats a lot less redundant code! Lets break down how this works starting with the array example above. We start out with a dog array that has two elements. The next line we are doing a couple different things at once. We are declaring the dog1 and dog2 variable and then assigning them the values of the dogs array. When destructuring an array what we put inside the &lt;code&gt;[]&lt;/code&gt; to the left of the &lt;code&gt;=&lt;/code&gt; will be the name of our new variables we are creating. To the right of &lt;code&gt;=&lt;/code&gt; is the array we are destructuring. Its that simple. Some interesting things to keep in mind: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;only the variable names you put in the &lt;code&gt;[]&lt;/code&gt; to the left of the &lt;code&gt;=&lt;/code&gt; will be created. If you had an array with 10 elements but only wanted the first two, all you have to do is put two variable names in the &lt;code&gt;[]&lt;/code&gt; and only the first two elements will be extracted.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&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="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;one&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;two&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
&lt;span class="nx"&gt;one&lt;/span&gt;
 &lt;span class="c1"&gt;//=&amp;gt; 1&lt;/span&gt;
&lt;span class="nx"&gt;two&lt;/span&gt; 
 &lt;span class="c1"&gt;//=&amp;gt; 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;you can skip elements in the array that you do not want to exact with &lt;code&gt;,,&lt;/code&gt;. So from our example above if we wanted the first two elements and then the 6th one we can do the following.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&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="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;one&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;two&lt;/span&gt;&lt;span class="p"&gt;,,,,&lt;/span&gt;&lt;span class="nx"&gt;six&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
&lt;span class="nx"&gt;one&lt;/span&gt; 
&lt;span class="c1"&gt;// =&amp;gt; 1&lt;/span&gt;
&lt;span class="nx"&gt;two&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 2&lt;/span&gt;
&lt;span class="nx"&gt;six&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;you can also setup default values if you like. If there is no element to extract for that position the default value will take over.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;food&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;eggs&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;sandwich&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;breakfast&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cereal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lunch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;salad&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dinner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;steak&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;food&lt;/span&gt;

&lt;span class="nx"&gt;breakfast&lt;/span&gt; 
&lt;span class="c1"&gt;// =&amp;gt; 'eggs'&lt;/span&gt;
&lt;span class="nx"&gt;lunch&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'sandwich'&lt;/span&gt;
&lt;span class="nx"&gt;dinner&lt;/span&gt;
&lt;span class="c1"&gt;// =&amp;gt; 'steak'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, if we did not have default values then the dinner variable would have been undefined.&lt;/p&gt;

&lt;p&gt;Now lets talk about objects. Object destructuring is very similar to array destructuring. Lets look at the myDogs object from earlier. The setup is the same as the array. Everything to the left of our &lt;code&gt;=&lt;/code&gt; will be our variable names and to the right will be what we are destructuring. One difference here is that we use &lt;code&gt;{}&lt;/code&gt; instead of &lt;code&gt;[]&lt;/code&gt;. The major difference is that we need to be aware of what are variable names are. In array destructuring we can call our variables whatever we want since arrays work off an index, but objects retrieve information with keys. So in order for Javascript to know what value we are trying to retrieve, we must use the key associated with that value in our &lt;code&gt;{}&lt;/code&gt;. There are two ways to do this. If the variable name is the same as the key then we can use just the keys in our &lt;code&gt;{}&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;boyDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;girlDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;boyDog&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;girlDog&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we want out variable names to be different than the keys we need to include &lt;code&gt;:&lt;/code&gt; when we are Destructuring.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;boyDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;girlDog&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;boyDog&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;youngestDog&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;girlDog&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;oldestDog&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDogs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, we are declaring two new variables the youngestDog and the oldestDog and then assigning the value of the boyDog key and girlDog key from the myDogs object.&lt;/p&gt;

&lt;p&gt;One last thing to keep in mind about object Destructuring is that you can have default values just like we did with arrays.&lt;/p&gt;

&lt;p&gt;There you have it, Destructuring in all its glory. The syntax can feel a little foreign when you start but once you give it time, it will become second nature.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Linear and Binary Search in Javascript</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 24 Oct 2021 19:33:23 +0000</pubDate>
      <link>https://dev.to/turpp/linear-vs-binary-search-in-javascript-4bom</link>
      <guid>https://dev.to/turpp/linear-vs-binary-search-in-javascript-4bom</guid>
      <description>&lt;p&gt;When preparing for technical interviews there are a ton a material to cover and prepare for. The most important thing is coming up with a solution that works and then later showing that you can refactor and optimize your solution. To help in coding problems that require you to search through a set of data there are two very easy ways to do this. Of course there are more advanced ways but these searching techniques are easy to remember and get the job done. You can always go back to refactor and optimize later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Linear Search
&lt;/h2&gt;

&lt;p&gt;This is the most basic form of searching. Its pretty simple, you just iterate through your data set one at a time till you find what you are looking for. This can be done with a simple loop. Linear search works on both sorted and unsorted data. Since we are going through are data point by point, that means in the worst case we will have to go through every element. If we have a very large dataset, this could take a long time. Here is an example of what a linear search looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;array&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;num&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&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="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What the code is doing is very simple. All we are doing is looking at each element of the given array and comparing it to the number passed in. Once it finds a match it will return true or if there is no match it will return false. This can be used on sorted or unsorted data but usually just on unsorted data. There are better solutions for sorted data like Binary search.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Search
&lt;/h2&gt;

&lt;p&gt;Binary Search is a way we can dramatically speed up our searching in large data sets. There is one important thing that you have to keep in mind with this technique. The data set has to be sorted for it to work. If you do this with an unsorted data set it will NOT work. The whole objective of Binary search is to reduce the size of the data we are looking through. We will divide our code and check to see if the value we are searching for is in the first half or the second half. This reduces the data we are searching through in half. We can keep repeating this reduction till we have our answer or no more data to reduce. &lt;/p&gt;

&lt;p&gt;To get a better Idea of how this works here’s a visual example:&lt;br&gt;
let searchData = [1,2,3,4,5,6,7,8,9,10]&lt;br&gt;
searching for = 8&lt;/p&gt;

&lt;p&gt;=&amp;gt; [1,2,3,4,5] [6,7,8,9,10] //we can tell by looking that 8 is in the second array. This means we can remove the first array from consideration&lt;br&gt;
=&amp;gt; [6,7,8] [9,10] //We reduce again and can see that 8 is in the first array this time&lt;br&gt;
=&amp;gt; [6,7] [8] // 8 is in the second array&lt;br&gt;
=&amp;gt; [8] //this is equal to the value we are searching for and we are now done!&lt;/p&gt;

&lt;p&gt;If we did this same search in a linear fashion it would have took us 8 passes to get to our answer. With binary search we did the same task but with only 4 passes. Thats major! Imagine the difference if we had an array with thousands of elements. &lt;/p&gt;

&lt;p&gt;To do this in code there are a couple of steps you need to remember to get it to work. We need to start the function by creating 3 variables. The left point will represent the start of the array and the beginning of our sectioned array. The right point  will be the end of our sectioned array. Lastly, the midpoint will be the point in our array where we compare our value to see what half our value will be in. Once we create these variables it is time to start searching. We do this with a while loop. We are going to do our divide and conquering till we either find our solution or our left variable is greater than our right variable. &lt;/p&gt;

&lt;p&gt;In our while loop depending on if our search value is bigger or smaller than our midpoint will determine what variable we reassign. If our search value is greater than our midpoint then we know everything to the left of our midpoint is to small. We then move our left point to what our midpoint is. We can actually move it one spot past our midpoint because we know that our midpoint is not equal to our value. Once we do that, we reduced the size of the array we are looking at. We recalculate our midpoint inside of this reduce section and repeat the process. Here is what it looks like in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;leftPoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;rightPoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;midPoint&lt;/span&gt; &lt;span class="o"&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;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;leftPoint&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;rightPoint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

   &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;midPoint&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;leftPoint&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;  &lt;span class="nx"&gt;rightPoint&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;number&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;midPoint&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;rightPoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;midPoint&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;leftPoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;midPoint&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="nx"&gt;midPoint&lt;/span&gt; &lt;span class="o"&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;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;leftPoint&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;rightPoint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&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="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;midPoint&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&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 whole premise of Binary search is to keep reducing your data set till you find your solution. This greatly reduces the time it takes to find a value in a large data set. Remember this only works for sorted data. If you have unsorted data you, will need to either sort it or use a technique like the Linear search or something similar. &lt;/p&gt;

&lt;p&gt;To wrap everything up, searching is a very important part of programming. There are two elementary ways of searching that are easy to implement when under pressure during a coding interview. The Linear search is the most stream line and works with unsorted data. The Binary search is much quicker but only works on sorted data.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>(Arrow, Functions) =&gt; in Javascript</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 17 Oct 2021 05:36:46 +0000</pubDate>
      <link>https://dev.to/turpp/arrow-functions-in-javascript-1m42</link>
      <guid>https://dev.to/turpp/arrow-functions-in-javascript-1m42</guid>
      <description>&lt;p&gt;Thanks to ES6 we have an alternative way to declare functions in our JavaScript code. The syntax is quite a bit different than the traditional way but once you get the hang of it you'll fall in love. This article will be a short and sweet overview of arrow functions. Let me know in the comments if you like this short and example based article or if you like more detailed explanations.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Arrow Function
&lt;/h2&gt;

&lt;p&gt;An Arrow function is nothing but a short hand way for declaring a function. The easiest way to get a grasp of this syntax is to convert the traditional function declaration into an arrow function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;First:&lt;/strong&gt; We do not need the &lt;code&gt;function&lt;/code&gt; keyword so lets remove it and assign the function to a variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//arrow conversion&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Second:&lt;/strong&gt; We are getting close. Instead of using the &lt;code&gt;(){}&lt;/code&gt; we use &lt;code&gt;=&amp;gt;&lt;/code&gt;. I wonder where it gets its name from?? Lets changes those out and move everything on one line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//arrow conversion completed&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tada!!! It is that easy. Now there are some niche rules to keep in mind. Depending on the complexity of your function will determine the exact syntax you will use. &lt;/p&gt;

&lt;h4&gt;
  
  
  Parameters
&lt;/h4&gt;

&lt;p&gt;Depending on the number of parameters you have will determine if you need to use the &lt;code&gt;()&lt;/code&gt; or not. Easy rule to remember =&amp;gt; If you have 1 parameter no need for &lt;code&gt;()&lt;/code&gt;. If you have no parameters or more than one you will need to use the &lt;code&gt;()&lt;/code&gt; around your parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//one parameter so no ()&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//no parameter so must have ()&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;greetings&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi there!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//more than one parameter so must use ()&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayFullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;last&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;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="s2"&gt;`Hi my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&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;last&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  {} curly braces
&lt;/h4&gt;

&lt;p&gt;Depending on the body of you function will determine if you will need to use curly braces or not. If it there is only one return expression and everything is on one line you can omit the &lt;code&gt;{}&lt;/code&gt;. If there is additional logic that spans over multiple lines you must include the &lt;code&gt;{}&lt;/code&gt; and also use the &lt;code&gt;return&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//simple on liner = no need for {}&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sayName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//body has multiple lines so will need to use {} and return&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;findAvg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&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;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;avg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;avg&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a lot of syntactic sugar at work here. Arrow functions do not use the &lt;code&gt;function&lt;/code&gt; keyword. This is why we assign it to a variable. We can still use parameters in our function. This is the first thing we place before the &lt;code&gt;=&amp;gt;&lt;/code&gt;. The &lt;code&gt;=&amp;gt;&lt;/code&gt; is what we use instead of &lt;code&gt;(parameter){logic}&lt;/code&gt;. Anything to the left of the &lt;code&gt;=&amp;gt;&lt;/code&gt; will be the parameters and anything to the right will be the body of our function. One interesting thing about arrow functions is that the return is implied. If there is only one returning expression we can omit the &lt;code&gt;return&lt;/code&gt; keyword.&lt;/p&gt;

&lt;h2&gt;
  
  
  This
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;This&lt;/code&gt; is the main difference between the two different function types. &lt;code&gt;This&lt;/code&gt; can be confusing. If you are not aware of what &lt;code&gt;this&lt;/code&gt; is I encourage you to go look at some documentation to better understand. As far as arrow functions go, you can not bind &lt;code&gt;this&lt;/code&gt;. Normally &lt;code&gt;this&lt;/code&gt; would refer to the object it is being called on. This is not the case for an arrow function. In an arrow function &lt;code&gt;this&lt;/code&gt; is inherited from the parent scope and is normally the &lt;code&gt;window/global object&lt;/code&gt;. Keep this in mind when deciding which type of function to use.&lt;/p&gt;

&lt;p&gt;That is a short a simple overview of arrow functions. I hope you find this helpful and can use this as a quick refresher on how to compose your arrow functions. These are great for your simple functions and even better as callbacks. Let me know if you like this short code example heavy article or if you would rather have more detail and text describing the differences.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>... or ...? The Rest and Spread Operator</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 10 Oct 2021 03:29:22 +0000</pubDate>
      <link>https://dev.to/turpp/or-the-rest-and-spread-operator-1l1d</link>
      <guid>https://dev.to/turpp/or-the-rest-and-spread-operator-1l1d</guid>
      <description>&lt;p&gt;One thing that I have always respected about coding is how everything is cut and dry. There are no double meaning words like in the English language. Like ship for example! Am I talking about a boat or about Amazon Prime? We have keywords in programming languages for a reason. Then ES6 comes along and gives us the &lt;code&gt;rest&lt;/code&gt; and &lt;code&gt;spread&lt;/code&gt; operator. They both have the same &lt;code&gt;...&lt;/code&gt; syntax but their use varies widely. In this short article I will explain what each operator is and share some examples. &lt;/p&gt;

&lt;h2&gt;
  
  
  ...Rest
&lt;/h2&gt;

&lt;p&gt;The rest operator helps us manage parameters of a function. It allows us to create a function that takes a variable number of arguments. This is much different than the traditional way of declaring functions. What the &lt;code&gt;...&lt;/code&gt; does is convert the arguments we give it into an array. From there we can access each argument the same way you would with any array. The syntax for the &lt;code&gt;rest operator&lt;/code&gt; is very simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//place ... in front the name you want for your array of arguments&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;someFunc&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="c1"&gt;//When this function is called and arguments are passed in we will have an array of the arguments called args&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;argument&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;args&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;argument&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;someFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; 1&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; 2&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt; 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some important things to remember about the &lt;code&gt;rest operator&lt;/code&gt;. The rest operator should always be your last parameter and the &lt;code&gt;rest operator&lt;/code&gt; is used only use during function declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//the first argument passed will be ownerName the rest of the arguments will be placed in an array called dogNames&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;ownerAndDogs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ownerName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;dogNames&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="s2"&gt;`Hi my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ownerName&lt;/span&gt;&lt;span class="p"&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;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="s2"&gt;`I have &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dogNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; dog(s)`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Their names are &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;dogNames&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;name&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;ownerAndDogs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tripp&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt;Hi my name is Tripp&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt;I have 2 dog(s)&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt;Their names are&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt;Ada&lt;/span&gt;
&lt;span class="c1"&gt;//=&amp;gt;Taz&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ...Spread
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;spread operator&lt;/code&gt; is used to spread an array. There are two main use cases for this operator. The first is when we invoke our function. If we have a function that has multiple parameters and an array that contains the data we want to pass in as an argument, we can use the spread operator to spread the array out. This will make each element of the array a separate argument that we are passing into our function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//array to spread&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogNames&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;//function that requires two arguments when invoked&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sayDogNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dog1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dog2&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;dog1&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;dog2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//using the spread operator to spread my array into the two arguments needed for the function&lt;/span&gt;
&lt;span class="nx"&gt;sayDogNames&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;dogNames&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the array you are trying to spread has more elements than is needed in your function, it will still work. The function will just used the first couple of elements it needs to fulfill its required arguments. The rest of the elements will be ignored. &lt;/p&gt;

&lt;p&gt;The second main use case for the &lt;code&gt;spread operator&lt;/code&gt; is to make duplicates. Arrays are a non-primitive data type in JavaScript. This means that they are passed by reference not value. We can use the spread operator to pass the value of an array. That way we can modify it without worrying about harming the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&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="c1"&gt;//the spread operator spreads the array into individual elements of the new array instead of passing by reference.&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arrayCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;arrayCopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&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="c1"&gt;//array =&amp;gt; [1,2,3,4]&lt;/span&gt;
&lt;span class="c1"&gt;//arrayCopy =&amp;gt; [1,2,3,4,5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you have it. The &lt;code&gt;spread&lt;/code&gt; and &lt;code&gt;rest&lt;/code&gt; operator may look the same but they do two different things. An easy way to keep them apart is to remember that the &lt;code&gt;...rest&lt;/code&gt; is used in function declarations and the &lt;code&gt;...spread&lt;/code&gt; is used when invoking a function or copying an array. I hope this article helps clear any confusion that surrounds &lt;code&gt;...&lt;/code&gt; and &lt;code&gt;...&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>The React Lifecycle</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 03 Oct 2021 22:09:31 +0000</pubDate>
      <link>https://dev.to/turpp/the-react-lifecycle-3635</link>
      <guid>https://dev.to/turpp/the-react-lifecycle-3635</guid>
      <description>&lt;p&gt;Wait! React has a lifecycle? Is this the web form of the Terminator? No humankind is safe! React is such a great frontend tool. For those unaware, React uses components to control what is rendered on the screen for the user. If you want to learn more about how React controls this with the Virtual DOM check out my article &lt;a href="https://dev.to/turpp/what-is-the-virtual-dom-in-react-3afn"&gt;What is the Virtual DOM in React&lt;/a&gt;. React Class Components have a built in lifecycle that gives them even more utility. Every react component has 3 phases of its life. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mounting&lt;/li&gt;
&lt;li&gt;Updating&lt;/li&gt;
&lt;li&gt;Unmounting&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As a developer we have access to unique methods in each phase of the components lifecycle. In this article I will discuss what each phase is and also some of the common methods we have access to. &lt;/p&gt;

&lt;h2&gt;
  
  
  Mounting
&lt;/h2&gt;

&lt;p&gt;This is the very first phase in a components life. The lifecycle methods included in this phase are designed to create/setup and put the component in view. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;constructor()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;very first lifecycle method called&lt;/li&gt;
&lt;li&gt;sets the initial state of the component and binds event handler methods&lt;/li&gt;
&lt;li&gt;if there is no state or methods to bind you don’t need to include this in your component&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;render()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt; only required method in a class component&lt;/li&gt;
&lt;li&gt; this is where you place your JSX to get rendered onto the DOM.&lt;/li&gt;
&lt;li&gt; needs to be pure in nature. Meaning that it returns the same thing every time under the same circumstances. If you need to interact with the browser or change state make sure to use other lifecycle methods and not &lt;code&gt;render()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;componentDidMount()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;called right after the component is rendered.&lt;/li&gt;
&lt;li&gt;since its called after its rendered you have access to DOM nodes.&lt;/li&gt;
&lt;li&gt;place to make network request to APIs etc.
only called on initial rendering&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Updating
&lt;/h2&gt;

&lt;p&gt;We know that when state or props change in a component it will trigger a re-render. The lifecycle methods in this phase gives us control over the re-render and allows the component to update.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;shouldComponentUpdate()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;called when new props are received&lt;/li&gt;
&lt;li&gt;used to let React know if the new props should trigger a re-render or not.&lt;/li&gt;
&lt;li&gt;defaults to true and triggers a re-render and if returns false will not re-render&lt;/li&gt;
&lt;li&gt;used for performance optimization&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;render()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;automatically gets called&lt;/li&gt;
&lt;li&gt;same as before. Puts the updated component on the DOM.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;componentDidUpdate()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;gets called after the re-render&lt;/li&gt;
&lt;li&gt;works just like &lt;code&gt;componentDidMount()&lt;/code&gt; but gets called during updating phase and re-renders&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Unmounting
&lt;/h2&gt;

&lt;p&gt;This phase happens as our component rides off into the sunset. This is were we would preform any clean up operations. Once this phase is complete this component will be destroyed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;componentWillUnmount()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;invoked right before a component is unmounted&lt;/li&gt;
&lt;li&gt;used to preform any clean up operations that was created earlier. (timers, network request, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Functional Components and Hooks
&lt;/h2&gt;

&lt;p&gt;Lifecycle methods used to only be available to class components. This has since changed with the introduction of React Hooks. We use the &lt;code&gt;useEffect&lt;/code&gt; hook to access these methods. Accessing these lifecycle methods is a bit different from class components. I may do a separate article about this in the future but in the mean time I encourage you to check out the React documentation on this &lt;a href="https://reactjs.org/docs/hooks-effect.html"&gt;https://reactjs.org/docs/hooks-effect.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thats React components lifecycle in a nutshell. There are more lifecycle methods in each of the phases, but they are used for very specific cases. To learn more detail about the above methods or to dig a little deeper on the more rare lifecycle methods check out the &lt;a href="https://reactjs.org/docs/state-and-lifecycle.html"&gt;React documentation&lt;/a&gt;. &lt;br&gt;
Knowing more about the different phases of a component and the lifecycle methods associated with each phase will do nothing but make you a stronger React developer.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Lets get Loopy with Javascript</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Mon, 27 Sep 2021 01:59:24 +0000</pubDate>
      <link>https://dev.to/turpp/lets-get-loopy-with-javascript-nh1</link>
      <guid>https://dev.to/turpp/lets-get-loopy-with-javascript-nh1</guid>
      <description>&lt;p&gt;Imagine a world where we had to manual go through every element in an Array. A world where were we have to write ten functions just get a count down from 10 to zero. My fingers and brain are already hurting from just thinking about it. Loops are one of the things we take for granted. In this article I am going to go over the different types of loops in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Loop?
&lt;/h2&gt;

&lt;p&gt;A loop in JavaScript is just a way for us repeat a task a set number of times. We can have loops to iterate through a data structure or have a loop repeat for eternity. There are two main types of loops: &lt;code&gt;for loop&lt;/code&gt; and &lt;code&gt;while loop&lt;/code&gt;. A &lt;code&gt;for loop&lt;/code&gt; will repeat until a condition turns false. A &lt;code&gt;while loop&lt;/code&gt; will repeat while a condition stays true. Depending on the condition you pass into the loop, you can get a &lt;code&gt;for loop&lt;/code&gt; and a &lt;code&gt;while loop&lt;/code&gt; to do the same things. Doing this is not best practice but technically it is possible. Generally, when we want to iterate through a collection or do something that involves a counter we will use a &lt;code&gt;for loop&lt;/code&gt;. If we want logic to run till a certain condition changes or if we want an infinite loop we will use a &lt;code&gt;while loop&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  For Statement
&lt;/h2&gt;

&lt;p&gt;This is the traditional way for declaring a &lt;code&gt;for loop&lt;/code&gt;. The &lt;code&gt;for statement&lt;/code&gt; takes in 3 different parameters. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;initial expression&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is where we establish the counter that we will manipulate&lt;/li&gt;
&lt;li&gt;example: &lt;code&gt;let i = 0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;condition expression&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is our condition that will determine if the loop continues or not. &lt;/li&gt;
&lt;li&gt;If condition is true loop continues&lt;/li&gt;
&lt;li&gt;if condition is false loop stops&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;increment expression&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;this is the logic that will change our initial expression&lt;/li&gt;
&lt;li&gt;After every successful loop this will run and change our counter variable&lt;/li&gt;
&lt;li&gt;if the condition is false and the logic inside our loop never runs this will not run either
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="c1"&gt;//some logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When creating a for loop, we first start with our counter. Normally this starts at 0 or 1 but it can be whatever you like. Then we establish our conditional statement. Generally this is setup to check our initial counter to some value. This is what will determine if the loop will continue or not. IMPORTANT: make sure that your conditional statement will eventually be false. If it never turns false you will have an infinite loop and cause your program to crash. Lastly, we establish how we want our counter to change. This is normally increase or decrease by one &lt;code&gt;++&lt;/code&gt; or &lt;code&gt;--&lt;/code&gt; but it can be anything you like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//counts down from 10 to 0.&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;i&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;
  
  
  For…Of Statement
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;For of statements&lt;/code&gt; are used to iterate though iterable objects like an Array. This statement will give you the values of each element in the Array. These are great when you want to preform logic on multiple elements in an array. The syntax for the &lt;code&gt;for of loop&lt;/code&gt; is much simpler than before. This statement takes in 2 parameters and will keep repeating till it reaches the end of the object you passed in.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;name of variable

&lt;ul&gt;
&lt;li&gt;this is what you want to name the variable that will represent each element&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;name of iterable object

&lt;ul&gt;
&lt;li&gt;This will be what we iterate through&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An easy way to remember this syntax is to read it like normal text. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&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="c1"&gt;//for each num of the numbers array do something&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="nx"&gt;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;num&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;
  
  
  for…in statement
&lt;/h2&gt;

&lt;p&gt;This is used when you want to iterate over the properties of an object. Before with the &lt;code&gt;for…of statement&lt;/code&gt; we iterated over the values of an iterable array. We use &lt;code&gt;for… in statement&lt;/code&gt; when we want to iterate through the properties of an object. This is very beneficial when you want to access the keys of an object and retrieve or modify their values. The syntax is just like the &lt;code&gt;for … of statement&lt;/code&gt; expect it uses the key word &lt;code&gt;in&lt;/code&gt; instead of &lt;code&gt;of&lt;/code&gt;. I wonder where it got its name?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="c1"&gt;//logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  While Statement
&lt;/h2&gt;

&lt;p&gt;This is our second type of main loop. The &lt;code&gt;while loop&lt;/code&gt; will keep repeating while the condition is true. Once it returns false the loop will stop. This condition will be checked before the logic inside the statement is executed. This means if the condition in the &lt;code&gt;while statement&lt;/code&gt; starts off as false, the logic will never run.When creating a while loop you need to make sure to include logic that will eventually cause your conditional to be false. This is similar to the increment expression from the &lt;code&gt;for loop&lt;/code&gt;. Instead of having it as an argument, you put it inside of your logic. If you want to have an infinite loop all you have to do is pass the Boolean value &lt;code&gt;true&lt;/code&gt; into the condition. True is always true and will never be false so the loop will never stop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&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="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;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;i&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  do…while statement
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;do while statement&lt;/code&gt; is very similar to the &lt;code&gt;while statement&lt;/code&gt;, but one key difference. Remember how that if the statement in the while loop starts off as false it will never run. The &lt;code&gt;do while statement&lt;/code&gt; works in the reverse way. It will run the logic first and then it will check the conditional to see if it needs to run again. This is great when you need the logic to run at least one time no matter what the conditional returns. To create a &lt;code&gt;do while statement&lt;/code&gt; we used the &lt;code&gt;do&lt;/code&gt; key word and add our logic and then include the &lt;code&gt;while&lt;/code&gt; keyword with the conditional after.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;do&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;conditional&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope all this talked technical talk didn’t make you go loopy. Loops our a foundational fundamental of JavaScript. The more you know about them the better you will be. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is the Virtual DOM in React?</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Mon, 20 Sep 2021 03:35:34 +0000</pubDate>
      <link>https://dev.to/turpp/what-is-the-virtual-dom-in-react-3afn</link>
      <guid>https://dev.to/turpp/what-is-the-virtual-dom-in-react-3afn</guid>
      <description>&lt;p&gt;What makes React.js so snappy and powerful? The Virtual DOM plays a major role in this. If you have ever worked with React, I am sure you heard of it but how comfortable are you with how it works? In this article I will give a brief overview of what the Virtual DOM is and how it works in React.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Virtual DOM
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://reactjs.org/docs/faq-internals.html"&gt;React Documentation&lt;/a&gt;, "The virtual DOM (VDOM) is a programming concept where an ideal, or “virtual”, representation of a UI is kept in memory and synced with the “real” DOM by a library such as ReactDOM."&lt;/p&gt;

&lt;p&gt;To understand the Virtual DOM, we need to take a step back and look at the DOM. DOM stands for Document Object Model. This is basically a structural representation of a web page. The DOM will break down the web page into nodes and objects that we can access and change. This is what allows us to use JavaScript to make our applications dynamic. Whenever we manipulate the DOM, this will cause what the user sees on the webpage to change. With how complex modern web design is, this can easily turn into a problem. &lt;/p&gt;

&lt;p&gt;Let's take a  simple list for example. When we decide to add/remove something from that list, this will change our DOM and cause it to rebuild and render the update. Even though we just made a change to one list item the whole webpage has to be rendered again and the DOM has to be updated. This is just a simple list. Imagine this on a much larger scale with todays Single Page Applications? This can lead to performance issues fast!&lt;/p&gt;

&lt;p&gt;This is where the Virtual DOM comes in to save the day! The Virtual DOM is a copy of the actual DOM. For every object on the DOM there is a copy of that object in the Virtual DOM. The Virtual DOM is stored in memory and the user does not see it. Whenever we update our state and props ,in React, the Virtual DOM gets updated. From there, React knows what to update or keep the same. This is how React can update just sections of a webpage instead of having to rebuild and render the whole webpage after any DOM manipulation like other frontend frameworks. &lt;/p&gt;

&lt;h2&gt;
  
  
  How the Virtual DOM Works
&lt;/h2&gt;

&lt;p&gt;Okay, now we know about the DOM and the Virtual DOM, how does it work in React? React actually uses 2 Virtual DOMs. One Virtual DOM is created to represent the changes. The other Virtual DOM is a copy of what it looked like before any changes were made. React will then compare these two Virtual DOMs to see what needs to be updated. So how does this look?&lt;/p&gt;

&lt;p&gt;Whenever we make a change to a state or props it will rebuild every element on the Virtual DOM. This may sound like this could lead to performance issues but remember this is just a copy in memory of the actually DOM. There is no rendering it on the screen. This is a very fast process. Once the updates are made to the Virtual DOM React will compare it to the "snapshot" of the previous Virtual DOM from before the changes where made. During this comparison React can see exactly what elements changed and needs to be updated. Only the elements that changed from the previous Virtual DOM will be rendered on the actual DOM. This is how React updates only what needs to be updated instead of having to rebuild and render an entirely new DOM when making any updates. &lt;/p&gt;

&lt;h2&gt;
  
  
  TLDR
&lt;/h2&gt;

&lt;p&gt;To recap briefly, the DOM (Document Object Model) is a structural representation of a webpage. It gives us access to the different elements of our page and effects what is rendered on the screen. The Virtual DOM is a copy of the actual DOM. The Virtual DOM is stored in memory and the user does not see this. React uses two Virtual DOM’s to control what is rendered and updated. Whenever one change is made to the Virtual DOM, all the elements will get rebuilt and create a new Virtual DOM. This new Virtual DOM will get compared to the previous Virtual DOM (from before the changes). The differences between the two Virtual DOMs will then be updated on the actual DOM. This helps to prevent unnecessary renderings and gives us control of changes to our webpage. &lt;/p&gt;

&lt;p&gt;I hope this short and sweet article helps shine some light on the Virtual DOM and how it works with React. Understanding this concept will make you a stronger React developer!&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A little about Arrays, ArrayList, LinkedList and HashMaps</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Mon, 13 Sep 2021 01:17:32 +0000</pubDate>
      <link>https://dev.to/turpp/a-little-about-arrays-arraylist-linkedlist-and-hashmaps-47i3</link>
      <guid>https://dev.to/turpp/a-little-about-arrays-arraylist-linkedlist-and-hashmaps-47i3</guid>
      <description>&lt;p&gt;When I first learned Java I was coming from a JavaScript background. It felt like I was in the wild west with JavaScript. It is dynamically typed so I can have a variable be one data type and change it whenever I want. I could start creating a function without knowing what the return would be and just figure it out or change it at a whim. Java put a stop to this right away. Java is a Static typed language. Whenever we define a variable or a method we must know exactly what that data type is or our program won’t even compile. Knowing what data types and how to manage them in Java is crucial to being a Java developer. This article is dedicated to Arrays, ArrayList, LinkedList and HashMaps. I’ll give a quick summary on what they are and how they work and give a little example of what it looks like.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrays
&lt;/h2&gt;

&lt;p&gt;Arrays are an object that allows you to store a collection of ordered values (elements) in a single variable. Arrays in Java have a set size. This is different to how an array in JavaScript works. When you create your array, you must know how many elements you want and what data type these elements will be. You can not add elements to an array. You can only modify them. If you create an array with 5 elements, you may not add a six. You will either have to replace an element with the new 6th one or create a new Array with 6 elements. &lt;/p&gt;

&lt;p&gt;Since elements in an Array are ordered you can access them by an index number. The index number is the position of the element in the array. IMPORTANT: Arrays start with an index of 0. If you want to access the first element in the array, the index will be &lt;code&gt;[0]&lt;/code&gt; not &lt;code&gt;[1]&lt;/code&gt;. To change the element of an Array you can access the element and set it equal to the new value.&lt;/p&gt;

&lt;p&gt;These are great to use when you have a predetermined number of values and need to access random elements throughout the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// creating an array of strings called dogs. This creates a new array with two elements.&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;dogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Ada"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Taz"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
        &lt;span class="c1"&gt;// This changes the value of the first element "Ada" to "Snoopy"&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s"&gt;"Snoopy"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;//You can also create an array without having the values. This will create an array with 4 elements.&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;randomNums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ArrayList
&lt;/h2&gt;

&lt;p&gt;ArrayList are very similar to Arrays. An ArrayList is a resizable array. This means you can add or remove elements. An ArrayList actually contains a regular Array that we discussed earlier. When you add an element to the ArrayList it will check to see if there is room in the array for the element. If there is not enough room it will create a new Array with the new size and remove the old one. This is done behind the scenes but its important to know.&lt;/p&gt;

&lt;p&gt;To use an ArrayList you must &lt;code&gt;import java.util.ArrayList;&lt;/code&gt; This will give you access to the different methods that come with ArrayList. IMPORTANT: Elements in an ArrayList are objects. If you want to create an ArrayList of a primitive data type you will need to use a wrapper class. &lt;code&gt;&amp;lt;Boolean&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;lt;Character&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;lt;Integer&amp;gt;&lt;/code&gt; etc. &lt;/p&gt;

&lt;p&gt;ArrayList are great for sorting and accessing data. If you need to access random elements inside of an Array and the Array size may change, ArrayList is a great option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.ArrayList&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//Creates an empty ArrayList of data type Strings&lt;/span&gt;
        &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// Add elements to the newly created ArrayList&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Ada"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Taz"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Snoopy"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;//removes(“the element at index 2”)&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;//prints out the first element of the ArrayList dogs&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  LinkedList
&lt;/h2&gt;

&lt;p&gt;LinkedList is very similar to an ArrayList. You might notice the List at the end of the name. This is because they both implement the List interface. This gives them a lot of the same characteristics and methods. What makes LinkedList different is in the way that they are constructed. Remember how an ArrayList contains and Array and will create and remove the Array as needed. A LinkedList stores its items in “containers”. This “container” holds your element. When you add new elements it creates new “container” and links it to a different “container” in the LinkedList. That is where it gets its name from. With the nature of how these work, it is more efficient to use a LinkedList when you want access to the first or last element of the array. &lt;/p&gt;

&lt;p&gt;To use LinkedList you must &lt;code&gt;import java.util.LinkedList’&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.LinkedList&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//This creates a new LinkedList of Strings that is empty&lt;/span&gt;
        &lt;span class="nc"&gt;LinkedList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LinkedList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;//This adds new elements to our LinkedList&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Ada"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Taz"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Snoopy"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;//This removes the last element of our LinkedList&lt;/span&gt;
        &lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;removeLast&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;//Both lines will print the first element of our LinkedList&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dogs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getFirst&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HashMap
&lt;/h2&gt;

&lt;p&gt;HashMaps are a bit different from what we talked about before. HashMaps can be think of as &lt;code&gt;key&lt;/code&gt; &lt;code&gt;value&lt;/code&gt; pairs. Before, when we wanted something we would get it by calling its index. HashMaps do not use an index to get values like Arrays do. To get a value from a HashMap you access it by the key associated with that value. You can have different data types for keys and values in a hasMap. This means you can have a &lt;code&gt;string key&lt;/code&gt; and a &lt;code&gt;int value&lt;/code&gt; if you wanted. HashMaps can make accessing specific values easy and quick. &lt;/p&gt;

&lt;p&gt;To use HashMaps you must &lt;code&gt;import java.util.Hashmap;&lt;/code&gt; When creating a HashMap we pass in the data type of both the key and value inside of &lt;code&gt;&amp;lt;key, value&amp;gt;&lt;/code&gt;. These are objects so we will need to use the associated wrappers for primitive data types. The first object passed will be the key data type and the second will be the value data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.HashMap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//creates a HashMap called studentGrades that have a key that is a string and a value that is a char&lt;/span&gt;
        &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;studentGrades&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;//adding to HashMap&lt;/span&gt;
        &lt;span class="n"&gt;studentGrades&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Tripp White"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'A'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;studentGrades&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Class Clown"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'F'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;studentGrades&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Teachers Pet"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'C'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;//changes the Teachers Pet to an A for good behavor ; )&lt;/span&gt;
        &lt;span class="n"&gt;studentGrades&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;replace&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Teachers Pet"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'A'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;


        &lt;span class="c1"&gt;//prints out the value of "Teachers Pet" key in the studentGrades HashMap&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;studentGrades&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Teachers Pet"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a basic outline of Arrays, ArrayList, LinkedList, and HashMaps. I hope this helps you in understanding Java and build some great applications. As always look at the documentation for a full description and the many methods that can be used with each one.&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
    </item>
    <item>
      <title>--css variables</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 05 Sep 2021 21:23:19 +0000</pubDate>
      <link>https://dev.to/turpp/css-variables-1o8a</link>
      <guid>https://dev.to/turpp/css-variables-1o8a</guid>
      <description>&lt;p&gt;Why in the world do do hex or rgb colors have to be so hard to remember? Not to mention how much of a pain it is to find and change them when you change your color scheme. CSS variables to the rescues! If you have never used CSS variables the time to start is now. They are widely supported across browsers and can make you styling a breeze.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are --css variables
&lt;/h2&gt;

&lt;p&gt;CSS variables are a way for you to assign certain css values to a keyword and reuse them throughout your application. CSS variables can have local or global scope and can be manipulated with JavaScript. Most often, they are used to help you manage your colors but you can use css variables many different ways. In the simplest form, a css variable is nothing but a keyword that has a value assigned to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;To declare and use a css variable is very simple. There are 3 main things you need to remember: &lt;code&gt;--&lt;/code&gt; &lt;code&gt;:root&lt;/code&gt; &lt;code&gt;var()&lt;/code&gt;. &lt;code&gt;—-&lt;/code&gt; is used whenever you assign and declare your variable. To create a variable you must put &lt;code&gt;—-&lt;/code&gt; in front of your variable name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c"&gt;/* my variable name is main-color and my value associated with it is #5a9e4b */&lt;/span&gt;
&lt;span class="py"&gt;--main-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#5a9e4b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;:root&lt;/code&gt; is how you declare global scope. Scope is basically where all you can access your variable from. Global scope means you have access throughout your css file. You can create a local variable by using the &lt;code&gt;—-variable-name&lt;/code&gt; inside of a class. A local variable means that you only have access to this variable locally inside that class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* This is declaring a global variable that I can access from anywhere in my css file. Anything inside of :root is global.*/&lt;/span&gt;
&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="py"&gt;-main-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#5a9e4b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* This is declaring a local variable. I can only access this variable inside of this class */&lt;/span&gt;
&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--main-text-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--main-text-size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;var()&lt;/code&gt; is how you call your variables. Remember a variable is nothing but a keyword that has a set value. To pass this value to a css property all you have to do is type the name of your variable inside of the &lt;code&gt;()&lt;/code&gt;. It’s that simple!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* creating a global variable for main-color */&lt;/span&gt;
&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="py"&gt;-main-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#5a9e4b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* passing the variable name into the var function. This will put #5a9e4b as the value to the color property. */&lt;/span&gt;
&lt;span class="nc"&gt;.someClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="n"&gt;-main-color&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;
  
  
  Fallbacks
&lt;/h2&gt;

&lt;p&gt;Unfortunately not all browsers are created equally. While most browsers are pretty robust its best practice to have some fallbacks in place. There is special syntax that you can use to have a fallback for your value. Its the same &lt;code&gt;var()&lt;/code&gt; as before but you add a second argument. &lt;code&gt;var(--main-color, blue);&lt;/code&gt; This will use your css variable &lt;code&gt;--main-color&lt;/code&gt; and if it is invalid or not defined it will then make the value equal to blue. The &lt;code&gt;var()&lt;/code&gt; only takes in two arguments and the second argument can be an additional css variable if you want. &lt;code&gt;var(--main-color, var(--ultimate-fallback));&lt;/code&gt; This will try to use &lt;code&gt;main-color&lt;/code&gt; first and if its invalid will then use the &lt;code&gt;--ultimate-fallback&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--main-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#5a9e4b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c"&gt;/* will try --main-color first. If invalid will use blue */&lt;/span&gt;
&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--main-color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this will not act as a fall back for browsers that do not support css variables. To create a fallback for this is a little extra work but possible. CSS reads one line at at time. You can have the same property with two different values for the same class and css will use the last one written. We can take advantage of this with our variables. You can hard code your fallback in your css class and then on the next line add your css variable. Css will read each line and if the browser does not support css variables it will then default to your hard coded fallback. If the browser does support css variables then it will use it since it was used after the fallback.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="py"&gt;--main-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#5a9e4b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c"&gt;/* will use --main-color since it is last color property written. If invalid will then use blue.*/&lt;/span&gt;
&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--main-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using JavaScript
&lt;/h2&gt;

&lt;p&gt;Since css varaibles have access to the DOM you can change them with JavaScript! You can make some really interesting user interfaces with this trick. To start create your css variables like you normally would. Then use &lt;code&gt;querySelector&lt;/code&gt; to get access to the &lt;code&gt;root&lt;/code&gt; element. Now that you have access to the root element, all you have to do is use the &lt;code&gt;setProperty()&lt;/code&gt; method to change the value of you variable. This will update the value and hence update your entire css file everywhere you used that variable. The &lt;code&gt;setProperty()&lt;/code&gt; method is a method on CSSStyleDeclaration Object. I won’t go into detail on this or the other methods you can use. I want to keep this article light and focused on css varaibles instead of JavaScript. Go to &lt;a href="https://www.w3schools.com/jsref/obj_cssstyledeclaration.asp"&gt;https://www.w3schools.com/jsref/obj_cssstyledeclaration.asp&lt;/a&gt; If you would like to learn more about what you can do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="py"&gt;-primary-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#5a9e4b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="n"&gt;-primary-color&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//gives me access to the root element&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;rootElement&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//this will change the style of my —-primary-color variable to red.&lt;/span&gt;
&lt;span class="nx"&gt;rootElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--primary-color&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;red&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;In the above example I have a css variable called &lt;code&gt;—-primary-color&lt;/code&gt; that is set to the value of &lt;code&gt;#5a9e4b&lt;/code&gt;. Then I make the color to all of my &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tags equal to my new variable. In the JavaScript section, I first create a variable that is equal to the root element. Then I can access my variable by using the &lt;code&gt;setProperty('variable name', 'new value')&lt;/code&gt; method. The first argument is the variable name and the second argument is the new value. Now all my &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; will have red text!&lt;/p&gt;

&lt;p&gt;You now have the knowledge needed to start using css varaibles in your applications. This will help increase developement speed, readability, and maintainability. If you enjoy this you can look into things like Sass to further extend your css capabilities.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>CSS Position Property</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sat, 28 Aug 2021 20:51:19 +0000</pubDate>
      <link>https://dev.to/turpp/css-position-property-1j60</link>
      <guid>https://dev.to/turpp/css-position-property-1j60</guid>
      <description>&lt;p&gt;We have all been there before. Randomly trying different CSS properties to try get your page layout correct. This brute force approach to problem solving can be frustrating. You will finally get one thing right but mess up something else and have no idea why! I am going to try to fix this dilemma for you with this article. Knowing what each type of positioning is in CSS and how they work will greatly speed up your workflow and allow you to make some pretty amazing things!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Position Property
&lt;/h2&gt;

&lt;p&gt;The CSS Position Property has multiple values that makes it seem overwhelming at first but I promise once you get the hang of it, its easy! The Position Property has 4 values that you need to understand. There are also properties that will fine tune your layout like &lt;code&gt;top&lt;/code&gt;, &lt;code&gt;left&lt;/code&gt;, &lt;code&gt;right&lt;/code&gt;, &lt;code&gt;bottom&lt;/code&gt;, and &lt;code&gt;z-index&lt;/code&gt;. Depending on which of the 4 values you use, will determine how those fine tuning properties will effect your layout. Don't worry I know I just packed a lot into those last two sentences. I am going to break down each of these positions to make it a little clearer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static
&lt;/h3&gt;

&lt;p&gt;I know you are familiar with &lt;code&gt;Static&lt;/code&gt; positioning! It is the default position for HTML elements. All static means is that the positioning is based on the normal flow of the page. Since everything is based on the normal flow of the page the fine tuning properties I mentioned earlier do not work with static. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;default positioning of HTML elements&lt;/li&gt;
&lt;li&gt;will position elements based on the normal flow of document&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;left&lt;/code&gt;, &lt;code&gt;top&lt;/code&gt;, &lt;code&gt;right&lt;/code&gt;, and &lt;code&gt;bottom&lt;/code&gt; do not work with this position&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hpxybqc55542ku3m14k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hpxybqc55542ku3m14k.png" alt="Static positioning example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Relative
&lt;/h3&gt;

&lt;p&gt;This property is named very well. &lt;code&gt;position: relative&lt;/code&gt; bases all positioning relative to its normal position. We are allowed to use the other position properties. When we set a top, left, right, or bottom it will adjust the position of the element according to where it would have been normally. One thing to keep in mind is when you make these adjustments there will be no automatic adjustments for the gaps you create. All other elements will adjust according to the original 'normal' position of the element while the position properties will adjust where it actually shows up on the page. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;positions elements relative to its normal position&lt;/li&gt;
&lt;li&gt;other elements will not adjust for any gaps and base their position off the relatives 'normal' position&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xb15vj2t7j7y17kp78p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xb15vj2t7j7y17kp78p.png" alt="Example of Relative positioning"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Fixed
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;position: fixed&lt;/code&gt; is used when you want to position an element to one place according to the viewport. When using our position properties with fixed, it will base all positioning according to the entire viewport. Once it's established, it will remain there even if the user scrolls. It is fixed in position! Important things to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;items positioned according to viewport&lt;/li&gt;
&lt;li&gt;other elements will not adjust to make up gaps&lt;/li&gt;
&lt;li&gt;elements are fixed and will not change there location on viewport when user scrolls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk7wunfsj57mb43ycqnkn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk7wunfsj57mb43ycqnkn.png" alt="Example of Fixed Positioning"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Absolute
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;position: absolute&lt;/code&gt; will position its element outside of the normal flow of the page. This means that other elements will not care where this is. This can lead to overlapping content if not managed properly. The absolute positioning will be based on its nearest positioned ancestor. It will ignore any none position elements and go and look for an element that has some position property attached. If it can not find one it will base its position on the document body. Since this is position outside of the normal flow of the document, other elements will not adjust for this elements position.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;positions outside of normal flow of page&lt;/li&gt;
&lt;li&gt;positioning is based on its nearest positioned ancestor&lt;/li&gt;
&lt;li&gt;if no positioned ancestors will base position on document body.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93q51tszwvc5zlw6nnjs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93q51tszwvc5zlw6nnjs.png" alt="Example of Absolute Position"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I changed my positions  to be &lt;code&gt;0px&lt;/code&gt; from the left it will overlap the content of its parent div.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwt5zzollbxgqsjod8bli.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwt5zzollbxgqsjod8bli.png" alt="Example of overlapping with Absolute Position"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If my absolute div does not have a position ancestor it will position based to the document body. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fooxrlzc174a3rqb0na2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fooxrlzc174a3rqb0na2d.png" alt="Example of absolute positioning when there is no position ancestor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Z-index
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;z-index&lt;/code&gt; is used to control overlapping elements. With the &lt;code&gt;z-index&lt;/code&gt; you can adjust what element is on top of each other. This works for position elements only. This will not work for static position elements. To control the overlapping you just give you &lt;code&gt;z-index&lt;/code&gt; a value. The largest number will be on top and the smallest number on bottom. You can use -1 if you want the element to always be in the very back of the document. If you do not give your elements a &lt;code&gt;z-index&lt;/code&gt; it will default to putting whatever element came last in your html on top and keep that order for all overlapping elements. In the example below I have overlapping elements but never established a &lt;code&gt;z-index&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;controls the order of overlapping elements&lt;/li&gt;
&lt;li&gt;largest number will be on top and smallest will be on bottom&lt;/li&gt;
&lt;li&gt;if no &lt;code&gt;z-index&lt;/code&gt; established will default to putting the last element in html on top&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F32moanjtpcx8a1jhex20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F32moanjtpcx8a1jhex20.png" alt="example of default z-index without any declared"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example below I added a &lt;code&gt;z-index&lt;/code&gt; to each div. This is how I reversed the overlap from before.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ka3c73ifkgt791bwgcb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ka3c73ifkgt791bwgcb.png" alt="Example of overlapping divs and z-index"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this article helps clear the confusion on CSS positioning and takes your page layouts to the next level. Next time your stuck on a frustrating page layout issue just take a step back reference this article and see how each of your divs are position. From there you can troubleshoot and get back on track in no time!!&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Common Array Methods in Javascript</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Mon, 23 Aug 2021 03:08:25 +0000</pubDate>
      <link>https://dev.to/turpp/common-array-methods-in-javascript-9p8</link>
      <guid>https://dev.to/turpp/common-array-methods-in-javascript-9p8</guid>
      <description>&lt;p&gt;Wether you are building the new facebook or studying for that next technical interview, you are going to be working with arrays. In Javascript and Array is an object that stores multiple values to a single variable. This data structure can be manipulated in many different ways with array methods. There are tons of array methods built into Javascript. In this article I’ll go over some very common methods and let you know what they look like and what they do!&lt;/p&gt;

&lt;h3&gt;
  
  
  unshift()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;unshift()&lt;/code&gt; will add elements to the beginning of the array. This method modifies the original array and will return the length of the array after adding the element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;unshift&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="c1"&gt;//returns 6&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  pop()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pop()&lt;/code&gt; will remove the last element of an array. This methods return value is the last element that it just removed. IMPORTANT: This will change the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//returns "Taz"&lt;/span&gt;
&lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  forEach()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;forEach()&lt;/code&gt; will iterate through the entire array and pass the element into a function where you can then do some logic. This methods return is dependent on what is inside of the function that the elements are being passed to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dog&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Who is a good dog? &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is!`&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;h3&gt;
  
  
  join()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;join()&lt;/code&gt; will take all the elements of an array and make them a string. This string will have all the elements separated by a comma. This method will return a string and will not modify the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;smallNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;smallNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// returns “1,2,3,4,5,6,20”&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  map()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; is very similar to the forEach(). They both iterate through an array but &lt;code&gt;map()&lt;/code&gt; will create and return a new array. This new array will be made based on the logic you pass inside of the function. This does not modify the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&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="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;//returns [4,8,12,16]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  filter()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;filter()&lt;/code&gt; creates a new array with elements of the original array that pass a test. This method returns a new array and does not alter the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;smallNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;smallNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns [1,2,3,4,5,6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  concat()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;concat()&lt;/code&gt; is used to join two or more arrays. This method will return a copy of the joined arrays. This way you don’t have to worry about changing the original arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;owners&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="s2"&gt;Tripp&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="s2"&gt;Melissa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogsAndOwners&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dogs&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;owners&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  every()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;every()&lt;/code&gt; will check to see if all the elements pass a certain test. If all elements pass the test it will return true. If even on element fails the test then it will return false. This does not modify the original array. It just returns a boolean value based on your test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;smallNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;smallNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns false since 20 is larger than 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  find()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;find()&lt;/code&gt; will look for the first element in the array that passes a condition. Its important to remember that if there are more than one match in the test array that it will only return the first match. If this method finds a match it will return true and stop. If it finds no match it will return undefined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;smallNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;smallNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//returns 20. To be specific it returns the second element since it is the first to pass the conditional.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  includes()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;includes()&lt;/code&gt; will look in the array for a specific element that you tell it to. If it finds the element it will return true if it does not find the element it will return false. It is important to remember that this is case sensitive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;snoopy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//returns false&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//returns false since "ada" is lower case and its capitalized in the array&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  reduce()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;reduce()&lt;/code&gt; can be a tricky method to get down but it is so useful in the right situations. This method will iterate through the entire array and return a single value that is the accumulated result of all the elements being passed through the reducer function. This will perform logic on one element and remember the results and then use that results on the next element in the array. You can also set the default value that the reducer will start. It defaults to 0 but if you prefer to start you calculations at 100 you can. This does not change the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;

&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//returns 6&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//returns 106&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  reverse()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;reverse()&lt;/code&gt; will reverse the order of the array. This will modify the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//returns ["Taz", "Ada"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  shift()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;shift()&lt;/code&gt; will remove the first element of an array and will return the element it removed. This method does change the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Ada&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="s2"&gt;Taz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//returns ["Ada"]&lt;/span&gt;
&lt;span class="nx"&gt;dogs&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="s2"&gt;Taz&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;h3&gt;
  
  
  slice()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;slice()&lt;/code&gt; will return a selection of elements in the array as a new array. You can be very creative with this method to get the section of the method you want. This method requires a start argument and and end argument. The end argument you pass is where you want it to stop, but it does not include that number. The start and stop locations are based off the array index. Its easy to forget this. This does not change the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;number&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// returns [2,3,4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  sort()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;sort()&lt;/code&gt; will modify the original array and sort it. This is great to use if you want to sort and array of strings. It will default to sorting it alphabetically. You can also sort numbers and it will default to sorting in ascending order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dogs&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="s2"&gt;Taz&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="s2"&gt;Ada&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&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="nx"&gt;dogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//returns ["Ada", "Taz"]&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//returns [1,2,3,4,5,6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  splice()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;splice()&lt;/code&gt; adds and removes elements from the array. This method requires an index to start at. It also takes an argument for how many you would like to remove and the new element(s) you want to add. Basically you tell it what element to start if/how many elements you want to remove and then the elements in the order that you want to add in that place. This changes the original array. It will return the removed elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;//splice(start, deleteCount, item1ToAdd, item2toAdd, etc);&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&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="c1"&gt;//returns [ ] because it did not remove anything&lt;/span&gt;
&lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you found this list of methods helpful. Bookmark this page and use it as a quick reference as you learn these methods and become an expert JavaScript programmer!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Simple Tailwind CSS Clean Up</title>
      <dc:creator>Thomas(Tripp) White </dc:creator>
      <pubDate>Sun, 15 Aug 2021 21:25:22 +0000</pubDate>
      <link>https://dev.to/turpp/simple-tailwind-css-clean-up-3fji</link>
      <guid>https://dev.to/turpp/simple-tailwind-css-clean-up-3fji</guid>
      <description>&lt;p&gt;Tailwind CSS is a utility first CSS framework. This allows you to create dynamic and beautiful webpages without having to go back and forth between CSS files. No more having to come up with crazy descriptive but short class names. All this power does come with some draw backs. One of the major draw backs is how messy you code can look, but no worries there is a way to clean this up. Today we will talk about base styles and extracting component classes.&lt;/p&gt;

&lt;p&gt;Tailwind CSS styles your applications by using utilities. Utilities are just specific class names that relate to some css property and value. This is great till you have tons of utilities listed like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-75"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Click me
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you want to reuse this element across your application. No problem, just copy and paste right?? Oh wait, what if I want to change the color of my text and background? Now I have to go find every place I pasted and change the utility one by one. This can be very frustrating and make bigger projects unmaintainable. The good news is that there are a couple of tricks to help this pain point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Base Styles
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS comes with a set of base styles called the preflight. These base styles are bare bones. This is both good and bad. The good is that it opens up for greater control of your styling but the bad is that it removes a lot of common stylings. For example an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; will look exactly the same. Margins are even removed from most elements. This means every time you put an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; you will have to add utilities every time to style it. This gets boring quick!&lt;/p&gt;

&lt;p&gt;To fix this you can set your own base styles. I would only recommend doing this if you know that a certain element will always be the same no matter where you use it. For example, if I had a design where I knew that my &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; would be a set size and a set font everywhere in my application, I would add it to my base styles. This way I can simply just type &lt;code&gt;&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&lt;/code&gt; instead of adding all the utilities needed. If I decide to change or add something later I can just simply modify my base style instead of finding all the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; across my application. &lt;/p&gt;

&lt;p&gt;This is very simple. All we have to do is open up our CSS file that has our tailwind setup. Below the setup, we can add our base styles by using the keywords &lt;code&gt;@layer&lt;/code&gt; and &lt;code&gt;@apply&lt;/code&gt;. The &lt;code&gt;@layer&lt;/code&gt; keyword tells Tailwind which “bucket” this set of custom styles belong to. In our example, we are telling Tailwind that these custom styles belong to base layer. This also tells tailwind to consider these styles for purging. The &lt;code&gt;@apply&lt;/code&gt; keyword allows us to use tailwinds utilities in our own custom css.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;@layer&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;@apply&lt;/span&gt; &lt;span class="err"&gt;text-2xl;&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;Now every &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; in our document will start off with these utilities attached. Remember these are just our base styles.  We can still add more utilities in different parts of our application if we wanted. &lt;/p&gt;

&lt;h2&gt;
  
  
  Extracting Component Classes
&lt;/h2&gt;

&lt;p&gt;What do we do if we use the same component over and over again. Adding base styles to each element in that component is not ideal. The simplest way is to extract a component class. We do this just like we did earlier. Remember that the &lt;code&gt;@layer&lt;/code&gt; keyword tells what “bucket” our custom css belongs to? We just repeat the above but instead of using the &lt;code&gt;base layer&lt;/code&gt; we use &lt;code&gt;@layer components {}&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;@layer&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.btn-blue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;@apply&lt;/span&gt; &lt;span class="err"&gt;py-2&lt;/span&gt; &lt;span class="err"&gt;px-4&lt;/span&gt; &lt;span class="err"&gt;bg-blue-500&lt;/span&gt; &lt;span class="err"&gt;text-white&lt;/span&gt; &lt;span class="err"&gt;font-semibold&lt;/span&gt; &lt;span class="err"&gt;rounded-lg&lt;/span&gt; &lt;span class="err"&gt;shadow-md&lt;/span&gt; &lt;span class="py"&gt;hover&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;bg-blue-700&lt;/span&gt; &lt;span class="n"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;outline-none&lt;/span&gt; &lt;span class="n"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;ring-2&lt;/span&gt; &lt;span class="n"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;ring-blue-400&lt;/span&gt; &lt;span class="n"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;ring-opacity-75&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;Now in our code, all we have to do is add the class &lt;code&gt;btn-blue&lt;/code&gt; and our button is styled. If we want to change something about our button we just have to edit that extracted component class once and it updates every where for us. &lt;/p&gt;

&lt;p&gt;With these simple tricks you can quickly clean up your code and make it much easier to maintain. There are other neat tricks that can help streamline your use of Tailwind. I encourage you to go check out the documentation (its one of the best around). I hope you found this helpful and good luck with your upcoming projects! &lt;/p&gt;

&lt;p&gt;(all code examples are from Tailwind Docs &lt;a href="https://tailwindcss.com/docs"&gt;https://tailwindcss.com/docs&lt;/a&gt;)&lt;/p&gt;

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