JavaScript Loops Tutorial: for, while, do while
Loops let JavaScript repeat code without writing it twice. Learn the three core loop types, what each one does, and when to choose one over another.
Master JavaScript from basics to advanced
Loops let JavaScript repeat code without writing it twice. Learn the three core loop types, what each one does, and when to choose one over another.
A while loop repeats code as long as a condition stays true. Learn the syntax, see practical examples, and understand when a while loop is the right choice over a for loop.
The for loop is the most common way to repeat code in JavaScript. Learn the three-part syntax, how each part works, and how to write clean, readable for loops.
The do while loop guarantees the body runs at least once before checking the condition. Learn the syntax, when this behavior matters, and practical real-world use cases.
Looping through arrays is the most practical use of JavaScript for loops. Learn how to access each element by index, avoid off-by-one errors, and choose between for, for...of, and forEach.
A nested loop is a loop inside another loop. Learn how nested loops work and why the inner loop runs completely for each outer iteration, with grids and multi-dimensional data.
The break statement stops a loop immediately and jumps to the code after it. Learn how to exit loops early, break out of nested loops with labels, and use break inside switch statements.
The continue statement skips the rest of the current loop iteration and jumps to the next one. Learn how to cleanly filter out items without deeply nested if blocks.
An infinite loop freezes your program because the exit condition never becomes false. Learn the most common causes, how to spot them, and how to prevent every type of infinite loop in JavaScript.
Private class fields keep data truly hidden inside a class. Learn the # syntax for private fields, private methods, private getters and setters, and how they differ from the old underscore convention.
BigInt is JavaScript's primitive for arbitrarily large integers. Learn to create BigInts, perform operations, handle mixed-type rules, and use BigInt for precise math beyond Number's limits.
The Intl API formats dates, numbers, currencies, and lists for any locale without external libraries. Learn DateTimeFormat, NumberFormat, RelativeTimeFormat, and ListFormat with practical examples.