The While Loop in JavaScript
While Loop
The while loop repeats through a block of code, but only as long as a specified condition is true. Its condition can be a conditional statement that returns true or false. However, if the condition is always true, then the loop will not terminate and it will cause an error. Such loops are called endless loops and they can be very dangerous at certain times.
Syntax of while loop is:-
while(statement1){
// block of code to be executed as long as the condition is true
}