JavaScript break Statement
You are Here:
JavaScript break Statement
The break
statement terminates the current loop, or switch statement and transfers program control to the statement following the terminated statement.
break statement in for loop
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var txt = "";
for(var i = 0; i <= 5; i++){
if(i == 3)
break;
txt += i;
}
x.innerHTML = txt;
</script>
</body>
</html>
Syntax
break
break Statement in switch case
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var num = 0;
var txt = "";
switch(num){
case 0:
txt = "zero";
break; // Try to remove this break
case 1:
txt = "One";
break;
}
x.innerHTML = txt;
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.