Expressions
An expression is a piece of FQL code that produces a value.
Expressions appear throughout a query: on the right side of LET and VAR, inside RETURN, in function arguments, conditions, filters, object fields, array items, and other places where a value is expected.
In this example, "Ada", true, ["admin", "editor"], name, active, and LENGTH(roles) are all expressions.
Where expressions are used
Expressions can be used anywhere FQL expects a value.
Common examples include:
- variable assignments
- return values
- function arguments
- array items
- object field values
- filter conditions
- loop inputs
- conditional branches
The query uses expressions in several different positions:
usersis the input expression for theFORloop.user.active && user.age >= 35is the filter expression.user.nameis an object field value expression.CONCAT(user.name, " is active")is a function call expression.
Literal expressions
A literal expression writes a value directly in the query.
Literals are the most direct way to create basic values.
For the complete list of built-in value types, see the Values and Types section.
Variable references
A variable reference is an expression that reads the value of a variable.
The expression name evaluates to the value assigned by the earlier LET statement.
Variables are resolved from the current scope. A variable can only be referenced after it has been declared in a scope where it is visible.
Property access
Property access reads a field from an object or runtime-backed value.
Property access can be chained when nested values are being read.
For objects, the accessed property is matched by name. For runtime-backed values, the behavior depends on the value and the runtime that provides it.
Indexed access
Indexed access reads an item from a value by position or key.
Indexes are expressions too:
Indexed access is commonly used with arrays. Host values may also support indexed access if the runtime defines that behavior.
Operators
Operators combine expressions into larger expressions.
The expression price * quantity produces a number, and comparing it with >= 250 produces a boolean.
See the Operators section for the full list of supported operators and precedence rules.
Function calls
A function call is an expression that invokes a function and produces its result.
Function arguments are expressions too. The inner calls to UPPER are evaluated and passed as arguments to CONCAT.
For details on function declarations and calls, see the Functions section.
Collection expressions
A collection expression creates an array or object value.
Array items and object field values are expressions. They are evaluated in order and stored in the resulting collection.
Collections can contain any value type, including nested arrays and objects.
Object field names become property names in the resulting object.
Conditional expressions
A conditional expression selects a value based on a condition, using the ternary operator.
The condition is evaluated first. If it is true, the first branch is used. Otherwise, the second branch is used. Both branches are expressions.
See the Ternary Operator section for the full syntax, including the shortcut form.
Subquery expressions
Some query constructs can produce values and be used as expressions.
Nested query blocks can also be used this way:
A subquery expression evaluates a query block and uses its result as a value. This allows a query result to be assigned to a variable, returned as part of another value, or passed to a function.
See Subquery Expressions for more, including nesting and indexing.
Expressions and statements
Expressions produce values.
Statements describe query structure, control flow, or variable declarations.
For example, LET is a statement. The code on the right side of = is an expression:
RETURN is also a statement. The value after RETURN is an expression:
Only the expression parts of a statement can be nested inside other expressions.
Evaluation
Expressions are evaluated when the surrounding statement or expression is evaluated.
In this query, the object expression after RETURN is evaluated once for each item produced by the loop.
Expression evaluation follows the structure of the query. Nested expressions are evaluated as needed to produce the value of the outer expression.