Skip to content

Everything is an expression

if has no parentheses, requires braces, and yields a value:

let size = if n > 1000 { "large" } else { "small" }

Blocks after => are statement blocks whose final expression is the return value, matching JavaScript syntax rules such as requiring parentheses to return an object literal directly: (x) => ({ id: x }).

An if without else in value position has type ?T (“maybe absent”). This becomes the JSX conditional-rendering idiom in §12.

In statement position (a guard clause, or an imperative branch whose value you discard), if lowers to a plain TS if statement: diverging branches (return, raise, throw, continue, break) and an absent else are all legal, and no temporary or ternary is introduced. The canonical guard clause if !ok { raise Invalid(…) } reads exactly as it emits.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close