Source @ github

break

break – Terminates the current loop, switch, or label statement.

Description

break [label label]

Parameters

Name Description Type Default Optional
label label Yes

Examples

Example #1 – break example

Breaking out of a loop.

var i = 1; while (i <= 10) { console.log('Running loop # ' + i); if (i === 5) { console.log('Breaking out.'); break; } i++; }
Example #2 – break example

Breaking out of a label.

console.log('Before section label'); section: { break section; console.log('Never executed'); } console.log('After section label');
Example #3 – break example

Breaking out of nested labels.

section: { console.log('In section'); subSection: { console.log('In sub section'); break section; console.log('Never executed'); } console.log('Never executed'); } console.log('It can even be nested!');

External references