Sum of integers in an interval
A good addition is to add a check at the start of your function to check if your parameters are correct. This way you don't need extra if statements which helps for readability.


const isValidNum = (n) =&gt; typeof n === "number" &amp;&amp; n &gt;= 0;

const sumAll = function(lowEnd, highEnd) {
  if (!isValidNum(lowEnd) || !isValidNum(highEnd)) return "ERROR";

  let total = [];
  let sum = 0;

  if (lowEnd &lt;= highEnd) {
    for (let i = lowEnd; i &lt;= highEnd; i++) {
      total.push(i);
    }
  } else {
    for (let i = highEnd; i &lt;= lowEnd; i++) {
      total.push(i);
    }
  }

  for (let i = 0; i &lt; total.length; i++) {
    sum += total[i];
  };

  return sum;
}

console.log(sumAll(1, 4));
console.log(sumAll(4, 1));
console.log(sumAll("1", 4));
console.log(sumAll(1, "4"));
console.log(sumAll(1, -4));
console.log(sumAll(-1, -4));



Another option is to check for the highest and lowest number via Math.min() and Math.max(). This way the order of input doesn't matter and you don't have to write the loop twice.


const isValidNum = (n) =&gt; typeof n === "number" &amp;&amp; n &gt;= 0;

const sumAll = function(lowEnd, highEnd) {
  if (!isValidNum(lowEnd) || !isValidNum(highEnd)) return "ERROR";

  let total = [];
  let sum = 0;
  
  const lowest = Math.min(lowEnd, highEnd);
  const highest = Math.max(lowEnd, highEnd);

  for (let i = lowest; i &lt;= highest; i++) {
    total.push(i);
  }

  for (let i = 0; i &lt; total.length; i++) {
    sum += total[i];
  };

  return sum;
}

console.log(sumAll(1, 4));
console.log(sumAll(4, 1));
console.log(sumAll("1", 4));
console.log(sumAll(1, "4"));
console.log(sumAll(1, -4));
console.log(sumAll(-1, -4));



At last you could add a formula to calculate the total sum of a range of numbers. Which removes the need of loops. (More info about the formula here)


const isValidNum = (n) =&gt; typeof n === "number" &amp;&amp; n &gt;= 0;

const sumRange = (low, high) =&gt; ((high - low + 1) * (low + high)) / 2;

const sumAll = function(lowEnd, highEnd) {
  if (!isValidNum(lowEnd) || !isValidNum(highEnd)) return "ERROR";
  
  const lowest = Math.min(lowEnd, highEnd);
  const highest = Math.max(lowEnd, highEnd);

  return sumRange(lowest, highest);
}

console.log(sumAll(1, 4));
console.log(sumAll(4, 1));
console.log(sumAll("1", 4));
console.log(sumAll(1, "4"));
console.log(sumAll(1, -4));
console.log(sumAll(-1, -4));



Total revision with comments:


// Return true if "n" is positive and of type number, else return false
const isValidNum = (n) =&gt; typeof n === "number" &amp;&amp; n &gt;= 0;

// Formula for adding a range of numbers
const sumRange = (low, high) =&gt; ((high - low + 1) * (low + high)) / 2;

function sumAll(lowEnd, highEnd) {
  // Return "ERROR" if arguments are invalid
  if (!isValidNum(lowEnd) || !isValidNum(highEnd)) return "ERROR";

  // Find highest and lowest number
  const lowest = Math.min(lowEnd, highEnd);
  const highest = Math.max(lowEnd, highEnd);

  // Return added numbers
  return sumRange(lowest, highest);
}

console.log(sumAll(1, 4));
console.log(sumAll(4, 1));
console.log(sumAll("1", 4));
console.log(sumAll(1, "4"));
console.log(sumAll(1, -4));
console.log(sumAll(-1, -4));



PS: I really like the way your tests are written. nicely clean and concise.