DEV Community

Cover image for JavaScript While Loop
Karthick (k)
Karthick (k)

Posted on

JavaScript While Loop

Introduction to the JavaScript while loop statement

The while loop executes a block of code as long as a specified condition is true. In JavaScript, this loop evaluates the condition before each iteration and continues running as long as the condition remains true.

Syntax:

while (expression) {
// statement
}

Basic JavaScript while loop example

The following example uses the while statement to output the odd numbers between 1 and 10 to the console:

Top comments (0)