JavaScript - While Loop

The while loop in JavaScript is used to repeatedly execute code while a specified condition is true. The code inside the loop will be executed as long as the condition is true.


while (condition) {

  // code to be executed while condition is true


It's important to have a way to update the condition in the loop, otherwise the loop will run indefinitely and lead to an infinite loop.