
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is break statement in JavaScript?
The break statement is used to exit a loop early, breaking out of the enclosing curly braces.
You can try to run the following to learn how to work with break statement in JavaScript. The following example illustrates the use of a break statement with a while loop. Notice how the loop breaks out early once x reaches 5 and reaches to document.write (..) statement just below to the closing curly brace −
Example
<html> <body> <script> var x = 1; document.write("Entering the loop <br/> "); while (x < 20) { if (x == 5) { break; // breaks out of loop completely } x = x +1; document.write( x + "<br/>"); } </script> </body> </html>
- Related Articles
- What is PowerShell Break statement?
- PHP break Statement
- Break Statement in C/C++
- Break statement in Dart Programming
- Break statement in Lua Programming
- How can I use a label with break statement in JavaScript?
- What is a break statement in Java and how to use it?
- What is if statement in JavaScript?
- What is continue statement in JavaScript?
- Java break statement with switch
- What is Switch...case statement in JavaScript?
- What is while loop statement in JavaScript?
- What is for loop statement in JavaScript?
- What is a block statement in JavaScript?
- How to use the break statement to come out of a loop in JavaScript?

Advertisements