MDN self-hosted library · e01.org

Control flow and error handling

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
{
  statement1;
  statement2;
  // …
  statementN;
}
js
while (x < 10) {
  x++;
}
js
> var x = 1;
> {
>   var x = 2;
> }
> console.log(x); // 2
>
js
if (condition) {
  statement1;
} else {
  statement2;
}
js
if (condition1) {
  statement1;
} else if (condition2) {
  statement2;
} else if (conditionN) {
  statementN;
} else {
  statementLast;
}
js
if (condition) {
  // Statements for when condition is true
  // …
} else {
  // Statements for when condition is false
  // …
}