Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ShockScript: Patterns

Matching patterns may be used in a number of contexts, including variable bindings, try..catch clauses, switch type cases, if..let and assignment left-hand sides.

Where applicable, expressions are disambiguated into those patterns, in which case any incompatible or illegal expression results in a syntax error; for example, an expression is disambiguated into a pattern inside an assignment whose left-hand side is either an array or object literal.

Syntax

    Pattern :
      [lookahead ≠ undefined if pattern is nested] IdentifierPattern
      ArrayPattern
      ObjectPattern
      ConstantPattern [if pattern is nested]
      Pattern NonNull
    TypedPattern :
      Pattern [lookahead ≠ :]
      Pattern : TypeExpression