title: Explain how this javascript codes sums two numbers and those between them
body: <p>I'm taking javascript lessons and I'm currently doing some little projects.</p>
  
  <p>One project is this:
  <em>Given two integers, which can be positive and negative, find the sum of all the numbers between including them too and return it. If both numbers are equal return a or b.</em></p>
  
  <p>One of the solutions I've found is this :</p>
  
  <pre><code>function GetSum(a, b) {
      if(a == b) {
          return a
      }
      else if (a &lt; b) {
          return a + GetSum(a+1, b)
      } else {
          return a + GetSum(a-1, b)
      };
  }
  console.log(GetSum(-1, 2));
  </code></pre>
  
  <p>Please, I would like an explanation on why the code works.</p>
  
  <p>...and, I will like to know why the code below is always returning 0  </p>
  
  <pre><code>function GetSum(a, b) {
      let lower, higher;
      let result = 0;
      //return either of it if they are equal
      if(a == b) {
          return a;
      } else {
          if(a &gt; b) {
              higher = a;
              lower = b;
          } else {
              higher = b;
              lower = a;
          }
          for(i = lower; i &lt;= higher; i++) {
              result += i;
          }
      }
      return result;
  }
  console.log(GetSum(3, 9))
  </code></pre>
  
  <p>Thanks in advance</p>