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

Your code is fine.

Keep it simple:

var res = (n * (n+1)) / 2;

Wiki.

Leave a Comment