Benchmark your JS code!
const n = 5000000; const res = (n * (n + 1)) / 2;
const n = 5000000; let res = 0; for(let i = 1; i <= n; i++) { res += i; }