If let statement
The if..let statement may be used for pattern matching on algebraic data types.
if (let Plus(10, right) = exp) {
//
}
It may also be used for extracting a non-nullable variable from a test expression, without using a matching pattern; that is, a regular identifier binding.
if (let node = parseAtom()) {
//
}
if..let can also be useful for, say, iterator results.
if (let [x!,false] = characters.next()) {
//
} else {
break;
}
Syntax
-
IfLetStatementabbrev :
-
if ( IfLetVariable ) Substatementabbrev
if ( IfLetVariable ) SubstatementnoShortIf else Substatementabbrev
-
IfLetStatementfull :
-
if ( IfLetVariable ) Substatementfull
if ( IfLetVariable ) SubstatementnoShortIf else Substatementfull
-
IfLetStatementnoShortIf :
-
if ( IfLetVariable ) SubstatementnoShortIf else SubstatementnoShortIf
-
IfLetVariable :
-
VariableDefinitionKind VariableBindingallowIn