JavaScript Program to print sum of first 10 natural numbers

In this program, You will learn how to print the sum of the first 10 natural numbers in JavaScript.


for (init; condition; increment/decrement) {
    // statement
}

JavaScript Program to print sum of first 10 natural numbers

Example: How to print the sum of the first 10 natural numbers in JavaScript

let s = 0;
for (i = 1; i <= 10; i++) {
  s = s + i;
}
console.log("Sum of first 10 natural numbers:" + s);

Output:

Sum of first 10 natural numbers:55