title: Javascript forEach callback
body: <p>I'm diving into Javascript callbacks and stuff. I came around the forEach() function. The functioname says it all, loop through each object in a list.</p>
  
  <p>When I look into the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="nofollow">documentation</a> I see the following syntax:</p>
  
  <pre><code>arr.forEach(callback[, thisArg])
  </code></pre>
  
  <p>And the documentation also mentions the parameters</p>
  
  <pre><code>currentValue
  index
  array
  </code></pre>
  
  <p>I stumbled upon an easy example of a forEach implementation:</p>
  
  <pre><code>var friends = ["Mike", "Stacy", "Andy", "Rick"];
  
  friends.forEach(function (eachName, index){
       console.log(index + 1 + ". " + eachName);
  });
  </code></pre>
  
  <p>And this gives me the obvious output:</p>
  
  <pre><code> "1. Mike"
   "2. Stacy"
   "3. Andy"
   "4. Rick"
  </code></pre>
  
  <p>I can live with the behaviour about everything and the result it gives, but I want to know why this is working and I'm confused about this</p>
  
  <pre><code>...function (eachName, index)...
  </code></pre>
  
  <p>When and where or how are eachName and index being filled with the correct value? Or how can I see how <strong>forEach</strong> is implemented, cause I'm guessing that this one is doing the magic here? Or am I missing an important concept here?</p>