Loops in JavaScript

Ankit Maheshwari
3 min readOct 8, 2024

[14] JavaScript Basics to Advanced Series: In this article we will learn about If-else and Switch-case in JavaScript.

My articles are open for everyone; non-member readers can read the article by clicking this link.

Loops

Loops are used to repeate an action for a given number of times.
Suppose we want to display a message 5 times, there are two ways to do that:

  • One way of doing that is by copying and paste the same statement 5 times.
  • Or using Loops we can repeate a statement as many times as we want.

In JavaScript we have 5 types of Loops

All loops are used to repeate an action for a given number of times.

  • for loop
  • while loop
  • do-while loop
  • for-in loop
  • for-of loop

For loop

for (initialization; condition; increment) {
statement
statement2
...
}

In the example below, repeating for-loop for 5 times.

--

--

Ankit Maheshwari

Frontend/Backend Engineer (Angular, React Native, NodeJS, MongoDB)