This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.

Expressions and functions

Arithmetic, comparisons, boolean logic, field reads, and conditional expressions work where values are expected. Conditions must be booleans: a nonempty string, nonzero number, list, or option is not implicitly true.
text
count > 0 and not loading
selected != none
items.length > 0
busy ? "Working…" : "Save"
and, or, and not also accept &&, ||, and !. Logical operators and conditional branches short-circuit. Use parentheses around a composite node attribute or positional expression to make its boundary obvious.
A file-scope function is one typed expression:
contract
fn plural(n: number): string = n == 1 ? "item" : "items"
component CountLabel
view
text `3 ${plural(3)}`
Functions have no effects, cannot recursively call themselves or form cycles, and do not capture component state (they can read performanceNow()). Pass values as parameters. A fn with a standard function's name shadows it in free calls (round(1.5) calls the app's fn round). See the grammar reference for the complete standard-function list.
The web's string and array methods are written as methods, with their web names and meanings: title.trim(), title.includes(query), items.length, items.at(-1), price.toFixed(2). The rest of the standard functions are called as functions: first(items), round(n), formatNumber(n, "compact"). Writing trim(title) is refused with the method form to write instead, and a method Contract lacks (items.reduce(…)) is refused. first and at return options; at counts a negative index from the end. There is no items[0] syntax.
map and filter accept a callback with zero, one, or two parameters: the item and its zero-based index. The callback is a single expression, reads its lexical environment, and returns a value. filter requires a boolean. join accepts a list of strings, numbers, or booleans and a string separator.
text
derive names = people.map((person, i) => `${i + 1}. ${person.name}`)
derive adults = people.filter(person => person.age >= 18)
derive caption = names.join(", ")
Callbacks can build records. They cannot return view nodes. Use for to build repeated UI, not map. sortBy(people, person => person.name) orders a list by one key, stably. General closures, reducers, comparator sorts, and arbitrary list mutation belong in the data module when the supplied operations do not suffice.
Is this helpful
Last updated November 30, 2026
Exact Docs