Q: How to find the sum of all numbers between 1 and N using JavaScript

Let's try it using for loop


    numberSum = (n) => {
      let total = 0;
      for (let i = 1; i < n; i++) {
        total += i;
      }
      return total;
    }

    numberSum(10)
    

One simple way to achive this

n * (n + 1) / 2

Demo