Whenever we need to perform a task or an action repeatedly, we use loops. The first type of loop we'll be looking at is the for loop.
For example if we need to add up all the number from 1 to 5 and log the result to the console, we can do it like this;
1
2
3
letsum = 1 + 2 + 3 + 4 + 5;
console.log(sum);
How about if need to add all the numbers from 1 to 100? We could do it by writing each number let sum = 1 + 2 + 3 + 4 ... etc. but this would take a long time.
This is where we can use a loop, a for loop to be exact: