What is a While Loop in JavaScript?
A while loop in JavaScript is used to repeat a block of code as long as a condition is true.
It is helpful when you donβt know how many times the loop should run in advance.
let i = 1;
while (i <= 5) {
console.log(i);
i++;
}
Output
1
2
3
4
5
Top comments (0)