title: passing an array to a function but logs as undefined
body: <p>I have 2 event listeners and they both push the element that is clicked into 2 separate arrays. These console.log in the event listener functions as expected, however when I pass them into a <code>move</code> function they both return undefined.</p>
  <p>I've tried it with just passing the element that is selected into the function as well with the same result.</p>
  <pre><code>document.querySelectorAll('img').forEach(function(el) {
      el.addEventListener('click' , function(params) {
          el.classList.add('selected')
          selectedPieces.push(el)
          console.log(selectedPieces)
          moveBy(selectedPieces)
      })
  })
  
  document.querySelectorAll('.square').forEach(function(el) {
      el.addEventListener('click', function() {
          el.classList.add('target')
          targetPieces.push(el)
          console.log(targetPieces)
          moveBy(targetPieces)
      })
  })
  
  function moveBy(selected,target) {
      console.log(selected)
      console.log(target)
  }
  
  
  </code></pre>