---
title: "Expressions and functions"
description: "Arithmetic, comparisons, boolean logic, field reads, and conditional expressions work where values are expected."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Expressions and functions

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/learn/contract-for-humans/expressions-and-functions: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

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](https://exact.expo.dev/reference/contract-grammar/standard-functions-and-intrinsics.md).

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.
