title: javascript simple assertEqual test run result
body: <p>I am learning JS and this is something I could not understand even after watching tutorials online.</p>
  
  <p>the function <code>assertEqual</code> compare actual and expected values with strict equality, then log one of two messages to the console.</p>
  
  <pre><code>function assertEqual(actual, expected, testName) {
      if (actual === expected) {
          console.log("passed")
      } else {
          console.log('FAILED [' + testName + '] Expected "' + expected + '", but got "' + actual + '"')
      }
  }
  </code></pre>
  
  <p>The test case is supposed to return <code>passed</code> and <code>FAILED</code> respectively.</p>
  
  <pre><code>function multiplyByTwo(n) {
      return n * 2;
  }
  var output = multiplyByTwo(2); // returns 4
  assertEqual(output, 4, 'it doubles 2 to 4');
  // console output:
  // passed
  
  function multiplyByTwo(n) {
      return (n * 2) + 1; // an incorrect implementation
  }
  var output = multiplyByTwo(2); // returns 5
  assertEqual(output, 4, 'it doubles 2 to 4');
  // console output:
  // FAILED [it doubles 2 to 4] Expected "4", but got "5"
  </code></pre>
  
  <p>however, the results are both <code>failed</code>...</p>
  
  <pre><code>FAILED [it doubles 2 to 4] Expected "4", but got "5"
  FAILED [it doubles 2 to 4] Expected "4", but got "5"
  </code></pre>
  
  <p>If I change the test case, however, with variable names like below...</p>
  
  <pre><code>let actualOne = multiplyByTwo(2)
  let expectedOne = 4;
  let testNameOne = 'it doubles 2 to 4'
  
  assertEqual(actualOne, expectedOne, testNameOne) // passed
  
  let actualTwo = multiplyByTwo(2)
  let expectedTwo = 5;
  let testNameTwo = 'it doubles 2 to 4'
  
  assertEqual(actualTwo, expectedTwo, testNameTwo)
  </code></pre>
  
  <p>these returns</p>
  
  <pre><code>FAILED [it doubles 2 to 4] Expected "4", but got "5"
  passed
  </code></pre>
  
  <p>So my question is, why does the first trial not work? What am I missing?</p>