JavaScript – Summary of JavaScript Statements

This chapter introduced each of the JavaScript language’s
statements. Table 5-1 summarizes them,
listing the syntax and purpose of each.

Table 5-1. JavaScript statement syntax

Statement Syntax Purpose
break break
[ label];

Exit from the innermost loop or switch or from named enclosing
statement

case case
expression:

Label a statement within a switch

continue continue
[ label];

Begin next iteration of the innermost loop or
the named loop

debugger debugger;

Debugger breakpoint

default default:

Label the default statement within a switch

do/while do
statement while
( expression);

An alternative to the while loop

empty ;

Do nothing

for for( init;
test;
incr)
statement

An easy-to-use loop

for/in for
( var in
object)
statement

Enumerate the properties of
object

function function
name([ param[,...]])
{ body }

Declare a function named
name

if/else if
( expr)
statement1 [else
statement2]

Execute statement1 or
statement2

label label:
statement

Give statement the
name label

return return
[ expression];

Return a value from a function

switch switch
( expression) {
statements }

Multiway branch to case or default: labels

throw throw
expression;

Throw an exception

try

try {
statements }

[catch { handler
statements
}]

[finally { cleanup
statements
}]

Handle exceptions

use strict "use
strict";

Apply strict mode restrictions to script or
function

var var
name [ =
expr] [ ,... ];

Declare and initialize one or more variables

while while
( expression)
statement

A basic loop construct

with with
( object)
statement

Extend the scope chain (forbidden in strict
mode)

Comments are closed.