title: Why should forEach be preferred over regular iterators?
body: <p>I was reading <a href="https://github.com/airbnb/javascript" rel="noreferrer">airbnb javascript guide</a>. There is a particular statement, that says:</p>
  
  <blockquote>
    <p>Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like for-in or for-of.</p>
  </blockquote>
  
  <p>The reason they give for the above statement is:</p>
  
  <blockquote>
    <p>This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.</p>
  </blockquote>
  
  <p>I could not differentiate between the two coding practices given:</p>
  
  <pre><code>    const numbers = [1, 2, 3, 4, 5];
  
      // bad
      let sum = 0;
      for (let num of numbers) {
       sum += num;
      }
      sum === 15;
  
      // good
      let sum = 0;
      numbers.forEach((num) =&gt; {
       sum += num;
      });
  
      sum === 15;
  </code></pre>
  
  <p>Could anyone explain, why should <code>forEach</code> be preferred over regular <code>for</code> loop? How does it really make a difference? Are there any side effects of using the regular <code>iterators</code>?</p>