<?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: Avinesh</title>
    <description>The latest articles on DEV Community by Avinesh (@avinesh49).</description>
    <link>https://dev.to/avinesh49</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%2F539010%2F67b9665d-f801-4027-a769-f6de9988ca5e.jpeg</url>
      <title>DEV Community: Avinesh</title>
      <link>https://dev.to/avinesh49</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/avinesh49"/>
    <language>en</language>
    <item>
      <title>The ...spread operator and the rest parameters</title>
      <dc:creator>Avinesh</dc:creator>
      <pubDate>Tue, 15 Dec 2020 09:49:13 +0000</pubDate>
      <link>https://dev.to/avinesh49/the-spread-operator-and-the-rest-parameters-3km4</link>
      <guid>https://dev.to/avinesh49/the-spread-operator-and-the-rest-parameters-3km4</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Spread operator&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;As the name suggests the spread operator spreads or expands an iterable such as an array or string into individual elements.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Few use cases&lt;/strong&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Adding elements of one array to new array.&lt;/li&gt;
&lt;li&gt;Passing an array as argument to a function.&lt;/li&gt;
&lt;li&gt;Array concatenation.&lt;/li&gt;
&lt;li&gt;Array copy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Adding elements of one array to new array
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr1 = [3,4,5];
var arr2 = [1,2,...arr1,6,7];
console.log(arr2); // output -&amp;gt; [1,2,3,4,5,6,7]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Passing an array as argument to a function
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addAll(a,b,c,d){
console.log(a+b+c+d); // output -&amp;gt; 10
}
var arr = [1,2,3,4];
addAll(...arr);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array concatenation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr1 = [1,2,3];
var arr2 = [4,5,6];
arr1 = [...arr1,...arr2];
console.log(arr1); // output -&amp;gt; [1,2,3,4,5,6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array copy
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr1 = [1,2,3,4];
var arr2 = [...arr1];
console.log(arr2); // output -&amp;gt; [1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Rest parameters&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;The rest parameter syntax allows us to represent an indefinite number of arguments as an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findProduct(...args){
var result = 1;
args.map((arg)=&amp;gt;{
result = result * arg;
});
return result;
}

console.log(findProduct(2,4,6)); // output -&amp;gt; 48
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Points to take away&lt;/strong&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Spread operator unpacks an iterable into individual elements.&lt;/li&gt;
&lt;li&gt;Rest parameter collects multiple individual elements and packs them into an array.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Functions: The bread and butter of JavaScript programming</title>
      <dc:creator>Avinesh</dc:creator>
      <pubDate>Sat, 12 Dec 2020 18:52:11 +0000</pubDate>
      <link>https://dev.to/avinesh49/functions-the-bread-and-butter-of-javascript-programming-3jh6</link>
      <guid>https://dev.to/avinesh49/functions-the-bread-and-butter-of-javascript-programming-3jh6</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Function&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;A &lt;em&gt;function&lt;/em&gt; in JavaScript is a piece of code contained within a block with a name associated to it. These are building blocks for almost every program that one tends to write. In simple words a &lt;em&gt;function&lt;/em&gt; is a subprogram which is capable of performing a specific task. &lt;/p&gt;

&lt;p&gt;There are a couple of ways by which we can create a function in JavaScript and we will go through each one them.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Function declaration&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;To create a function using function declaration you must use the &lt;strong&gt;&lt;em&gt;function&lt;/em&gt;&lt;/strong&gt; keyword followed by a name, followed by parenthesis which can have zero to any number of parameters and then followed by a pair of curly braces which holds the code to be executed.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Function declarations are hoisted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function square(x){
return x*x;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Function expression&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;To create a function using function expression you must follow the same steps as function declaration but you assign the function to a variable with a name which is the name of the function.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Function expressions are not hoisted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const square = function(x){
return x*x;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Arrow functions&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;These were introduced in ES6. Arrow functions helps you write shorter syntax by omitting the function keyword and replacing it with an arrow (=&amp;gt;) symbol which is made up of an equal to and a greater than symbol.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const square = (x) =&amp;gt; { return x*x; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just in case if there is only one parameter then you can even omit the parenthesis. If there is only a single expression to be returned then you can even omit the curly braces and the return keyword.&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; There is a difference between an expression and a statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const square = x =&amp;gt; x*x;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Points to take away&lt;/strong&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Function declaration is declared as a separate statement.&lt;/li&gt;
&lt;li&gt;Function expression is a part of another expression or a syntax.&lt;/li&gt;
&lt;li&gt;Arrow functions are handy for one-liners.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Reference:&lt;/em&gt; &lt;a href="https://eloquentjavascript.net/"&gt;Eloquent JavaScript&lt;/a&gt;&lt;/p&gt;

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