Skip to main content

Statements

Inside function bodies and closure blocks { … }, you can use the following statements.

Forms

StatementSyntax sketch
Returnreturn expr [ ';' ]
Failfail skip ( expr ) or fail stop ( expr ) (strategy + cause)
Constconst name = expr ';'
Letlet name = expr ';'
Assignname = expr ';'
If / elseif '(' cond ')' block ( else if ... )* [ else block ]
Whilewhile '(' cond ')' block
Forfor '(' binding in iterable ')' block
Do-whiledo block while '(' cond ')'
Breakbreak [ expr ] [ ';' ]
Continuecontinue [ ';' ]
Expressionexpr ';'

A semicolon may be omitted in some positions (e.g. return before }).

Blocks

A block is { zero or more statements }.

Module scope vs function body

At namespace scope, name = expr without const or let declares a module-level constant (this is how flow = … is written). Inside functions and closures, use const, let, or assignment statements as above.