<?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: Micheal Adisa</title>
    <description>The latest articles on DEV Community by Micheal Adisa (@michealadisa).</description>
    <link>https://dev.to/michealadisa</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%2F318818%2Fff442ce7-f2b7-4003-aeb9-4bbffefe7471.jpg</url>
      <title>DEV Community: Micheal Adisa</title>
      <link>https://dev.to/michealadisa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/michealadisa"/>
    <language>en</language>
    <item>
      <title>SPREAD IN JAVASCRIPT</title>
      <dc:creator>Micheal Adisa</dc:creator>
      <pubDate>Thu, 24 Sep 2020 14:14:00 +0000</pubDate>
      <link>https://dev.to/michealadisa/spread-in-javascript-3pa6</link>
      <guid>https://dev.to/michealadisa/spread-in-javascript-3pa6</guid>
      <description>&lt;p&gt;Oh i just finished washing my clothes i need them to be side by side on a line, i’ll spread them right? This sounds quite abstract, let’s see how this relates to javascript.&lt;/p&gt;

&lt;p&gt;The javascript &lt;strong&gt;spread&lt;/strong&gt; function is denoted by three dots &lt;code&gt;...&lt;/code&gt;. It was added to JavaScript in ES6 (ES2015) and is useful for adding items to an array, combining array and objects into a place and spreading an array out into a function’s arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [ 1, 2, 3, 4 , 5]
const array2 = [ 6, 7, 8, 9, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newArray = [...array1, ...array2]
console.log(newArray) // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like that! Our spread function works well as expected. You can go on and on to combine lots of array together into one (side by side 😀)&lt;/p&gt;

&lt;p&gt;Interesting stuff, it can also be used in Math functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const nums1 = [2, 7, 8, 5]
const nums2 = [4, 1, 9, 3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newNums = [...nums1, ...nums2]
console.log(Math.max(...newNums));    // 9
console.log(Math.min(...newNums));    //  1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you tried to log &lt;code&gt;newNums&lt;/code&gt; max number or minimum number without the spread syntax, you’ll get &lt;code&gt;NaN&lt;/code&gt;.&lt;br&gt;
Try this; c&lt;code&gt;onsole.log(Math.min(newNums));    //  NaN&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I’m sure you’re asking why this happened right?. Well, &lt;code&gt;Math.max&lt;/code&gt; or &lt;code&gt;Math.min&lt;/code&gt; and any other Math operator expects a list of numeric arguments, not a single array.&lt;/p&gt;

&lt;p&gt;This actually gives us a javascript superpower, love to see it! 😀. &lt;/p&gt;

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