<?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: wardov</title>
    <description>The latest articles on DEV Community by wardov (@wardov).</description>
    <link>https://dev.to/wardov</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%2F207512%2F38906644-217b-4363-ba56-758db605e8b0.jpeg</url>
      <title>DEV Community: wardov</title>
      <link>https://dev.to/wardov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wardov"/>
    <language>en</language>
    <item>
      <title>Javascript(ES6) Arrow Functions in a simple way:</title>
      <dc:creator>wardov</dc:creator>
      <pubDate>Thu, 04 Jun 2020 16:29:11 +0000</pubDate>
      <link>https://dev.to/wardov/javascript-es6-arrow-functions-in-a-simple-way-178f</link>
      <guid>https://dev.to/wardov/javascript-es6-arrow-functions-in-a-simple-way-178f</guid>
      <description>&lt;p&gt;Before digging into the code, we will start with the pros and cons of arrow functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Keeping track of this keyword without using &lt;code&gt;bind&lt;/code&gt; method&lt;/li&gt;
&lt;li&gt;Making code concise&lt;/li&gt;
&lt;li&gt;Shorter Presentation: what We mean by it is the fact that the Presentation of the code is shorter in volume, and for readability, it's a fantastic add-on to javascript.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cons:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Confusing Rules and Syntax&lt;/li&gt;
&lt;li&gt;Make code difficult to read
Let's talk about the choice of const over let in the definition of a variable or function. Why? The simple reason is that with &lt;code&gt;const&lt;/code&gt; we keep the value of the function untouchable.
We will begin the discussion with the first example by creating an anonymous function(which has no name) in the old javascript syntax:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&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;sayHello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HoussameEddine&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;WARDI&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;//Hello, HoussameEddine WARDI&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, let's talk about Arrow Functions ES6 syntax with this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first rule when we work with arrow functions, we remove the &lt;code&gt;function&lt;/code&gt; keyword.&lt;/li&gt;
&lt;li&gt;The second rule, we add the fat arrow symbol &lt;code&gt;=&amp;gt;&lt;/code&gt; between the function arguments and the body.&lt;/li&gt;
&lt;li&gt;The third rule, if we have one line only in the body we can remove the curly braces and the "return" keyword.
So, the final result will be as this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It gives us the same result, but you guessed that the code was concise and short.&lt;br&gt;
Example 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getStudentInfos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WARDI HoussameEddine&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;We wanted in this example to return an object in the &lt;strong&gt;ES6 syntax&lt;/strong&gt; , so, we conclude that we must add parentheses to the returned object as we saw in the last example.&lt;/p&gt;

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

&lt;p&gt;We saw in this article a great extent to javascript(ES6) that is Arrow functions and its pros and cons also;&lt;br&gt;
some real examples of this new feature.&lt;br&gt;
Thanks for reading the article, and if you have any questions related to the subject, LEAVE A COMMENT!&lt;/p&gt;

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