JavaScript while Loop Guide

JavaScript Logo

while Loop – Checks the condition **before** each iteration. Repeats an unknown number of times until the condition becomes false.

๐Ÿ‘‰ Syntax

while (condition) {
  // code executes while condition is true
}

๐Ÿงช Example

let n = 3;
while (n > 0) {
  console.log(n);
  n--;
}

Comments