<?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: Nsengiyumva Gershom La paix</title>
    <description>The latest articles on DEV Community by Nsengiyumva Gershom La paix (@gershomlapaix).</description>
    <link>https://dev.to/gershomlapaix</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%2F539611%2F4fc361f4-7438-4a83-b789-1efef5356a00.jpeg</url>
      <title>DEV Community: Nsengiyumva Gershom La paix</title>
      <link>https://dev.to/gershomlapaix</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gershomlapaix"/>
    <language>en</language>
    <item>
      <title>Strength of for-of loop over for-in and foreach loops in ES6.</title>
      <dc:creator>Nsengiyumva Gershom La paix</dc:creator>
      <pubDate>Wed, 06 Jan 2021 19:30:41 +0000</pubDate>
      <link>https://dev.to/gershomlapaix/strength-of-for-of-loop-over-for-in-and-foreach-loops-in-es6-3a23</link>
      <guid>https://dev.to/gershomlapaix/strength-of-for-of-loop-over-for-in-and-foreach-loops-in-es6-3a23</guid>
      <description>&lt;p&gt;Iterators are helpful to know because they serve as the basis for generators, which open new doors to asynchronous programming. ES6 came with for-of loop to beat some pitfalls found for-in loop. &lt;/p&gt;

&lt;h2&gt;
  
  
  Some drawbacks which are found in for-in loop:
&lt;/h2&gt;

&lt;p&gt;1.The values assigned to the index are the strings, not actual numbers.&lt;br&gt;
   Look here:&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;var&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;111&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;222&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;333&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;arr&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;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;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Never execute&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.for-in loop can iterate over the array elements in the arbitrary order.&lt;br&gt;
3.In foreach loop, we can't break out of the loop using break statement. Another drawback is that no returning from the enclosing function using return statement.&lt;/p&gt;
&lt;h2&gt;
  
  
  What for-of loop holds for us?
&lt;/h2&gt;

&lt;p&gt;1.It avoids all pitfalls of for-in loop and works with&lt;br&gt;
          &lt;strong&gt;break&lt;/strong&gt;, &lt;strong&gt;continue&lt;/strong&gt; and &lt;strong&gt;return&lt;/strong&gt; statements.&lt;br&gt;
   Here is an 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="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&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;arr&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;num&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;p&gt;2.It also works on strings, where it treats strings as a sequence of Unicode characters&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;of&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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ch&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;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Fellow guys, now I can recommend you to use this syntax sugar of for-of loop as it can help us in most cases. But, if you find some cases where you need such for-in and foreach loops, don't hesitate to use them as they are still useful.&lt;/p&gt;

&lt;p&gt;Thank you!!!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Greeting</title>
      <dc:creator>Nsengiyumva Gershom La paix</dc:creator>
      <pubDate>Sun, 13 Dec 2020 14:19:37 +0000</pubDate>
      <link>https://dev.to/gershomlapaix/greeting-53h1</link>
      <guid>https://dev.to/gershomlapaix/greeting-53h1</guid>
      <description>&lt;p&gt;Hey devs!!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
