JavaScript(JS) JS find the sum of natural numbers

here's how you can find the sum of natural numbers using JavaScript:

function sumOfNaturalNumbers(n) {
  let sum = 0;
  for (let i = 1; i <= n; i++) {
    sum += i;
  }
  return sum;
}
S‮ecruo‬:www.theitroad.com

In this function, we're using a loop to iterate through the natural numbers from 1 to n. We're adding each number to a sum variable, which is initially set to 0. Finally, we're returning the value of sum.

To use this function, you can call it with the desired value of n, like this:

console.log(sumOfNaturalNumbers(10)); // Output: 55

This will output the sum of the first 10 natural numbers, which is 55.