--- title: break slug: Web/JavaScript/Reference/Statements/break translation_of: Web/JavaScript/Reference/Statements/break ---
{{jsSidebar("Statements")}}

Break ifadesi içinde bulunduğu döngüyü , {{jsxref("Statements/switch", "switch")}}, or {{jsxref("Statements/label", "label")}} ifadelerini sonlandırır  ve programın kontrolünü sonlandırılan ifadeyi ardından takip eden ifadeye geçirir.

{{EmbedInteractiveExample("pages/js/statement-break.html")}}

Syntax

break [etiket];
etiket
İsteğe bağlıdır.İfade etiketini tanımlamakta kullanılır. Eğer belirtilen ifade bir döngü ya da {{jsxref("Statements/switch", "switch")}} değilse, mutlaka kullanılması gerekir.

Description

The break statement includes an optional label that allows the program to break out of a labeled statement. The break statement needs to be nested within the referenced label. The labeled statement can be any {{jsxref("Statements/block", "block")}} statement; it does not have to be preceded by a loop statement.

Examples

The following function has a break statement that terminates the {{jsxref("Statements/while", "while")}} loop when i is 3, and then returns the value 3 * x.

function testBreak(x) {
  var i = 0;

  while (i < 6) {
    if (i == 3) {
      break;
    }
    i += 1;
  }

  return i * x;
}

The following code uses break statements with labeled blocks. A break statement must be nested within any label it references. Notice that inner_block is nested within outer_block.

outer_block: {
  inner_block: {
    console.log('1');
    break outer_block; // breaks out of both inner_block and outer_block
    console.log(':-('); // skipped
  }
  console.log('2'); // skipped
}

The following code also uses break statements with labeled blocks but generates a Syntax Error because its break statement is within block_1 but references block_2. A break statement must always be nested within any label it references.

block_1: {
  console.log('1');
  break block_2; // SyntaxError: label not found
}

block_2: {
  console.log('2');
}

Specifications

Specification Status Comment
{{SpecName('ES1')}} {{Spec2('ES1')}} Initial definition. Unlabeled version.
{{SpecName('ES3')}} {{Spec2('ES3')}} Labeled version added.
{{SpecName('ES5.1', '#sec-12.8', 'Break statement')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-break-statement', 'Break statement')}} {{Spec2('ES6')}}  
{{SpecName('ESDraft', '#sec-break-statement', 'Break statement')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{Compat("javascript.statements.break")}}

See also