break Statement in JavaScript

The break statement or keyword in JavaScript is used to jump out from the current loop. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <script>
      for(let i=0; i<=10; i++)
      {
         if(i==4)
            break;
         console.log(i);
      }
   </script>
   
</body>
</html>

The output produced by above JavaScript example on break statement is:

js break statement

As you can see from the above example, if the value of i becomes 4, then the break statement gets executed to break out from the current loop or to stop the execution of the current loop.

JavaScript break Syntax

The syntax of break statement in JavaScript, is:

break;

Note - The break Vs. continue in JavaScript is described in its separate tutorial.

JavaScript Online Test


« Previous Tutorial Next Tutorial »