Syntax

JavaScript While Loop Syntax

In JavaScript, while loop: repeats while a condition is true — while (x < 10) { x++; }

Quick Answer

Syntax
while (x < 10) { x++; }
JavaScriptSyntax

While Loop

Code example
while (x < 10) { x++; }

Repeats while a condition is true.

Learn More

How to while loop in JavaScript

  1. Open your JavaScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

JavaScript While Loop Syntax

Use while (x < 10) { x++; }.

Related Syntax References

Frequently asked questions

What is the JavaScript syntax for while loop?

Use this pattern: while (x < 10) { x++; }

Can I copy this JavaScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this JavaScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify