offline version v3


9 of 264 menu

break statement

The break command performs a forced loop termination. It can break any loop: for, for-of, for-in, while.

Syntax

break;

Example

Let's determine if an array contains the number 3. If there is, output the phrase 'it's here' to the console and exit a loop:

let arr = [1, 2, 3, 4, 5]; for (let elem of arr) { if (elem == 3) { console.log('it's here'); break; // exits a loop } }

See also

enru