# Literals

Fauna Query Language (FQL) supports literal syntax for Numbers, Boolean values, Null, Strings, Arrays, Objects, and Functions.

## Boolean

A Boolean is a logical expression that evaluates to true or false.

The Boolean literals are `true` and `false`.

## Null

The Null literal represents the absence of a value. In Boolean expressions, `null` evaluates to `false`.

The Null literal is `null`.

## Number

A Number is a base 10 Int, decimal, or exponential.

Underscores can be used as separators instead of commas to improve readability but aren’t significant otherwise.

### Integer

An Int literal starts with a nonzero digit and don’t include a fractional or exponential part. A negative integer literal is preceded by the `-` character.

10
-250
1_000_000

Integer literals can have the following base representation:

Base Example

2

`0b1001`

8

`0o123`

10

`12345`

16

`0x12a3`

### Decimal

A decimal literal includes a fractional part. Internally, these are handled as Doubles.

1.0
0.1

### Exponential

E-notation is used for a decimal exponential literal: <decimal>e | E<exponent>:

1.2e23
3.4e-15

where,

• <decimal> is the base integer.

• `e` or `E` separator indicates an exponential literal.

• <exponent> is the signed integer exponent.

## String

A String literal is a sequence of single-quoted string values or double-quoted interpolated string values from the FQL-supported character set, and terminated by `null`.

Single-quoted Strings can include the `"` and `#` characters.

Double-quoted Strings can include the `'` character.

### Interpolated string

Double-quoted Strings support expression interpolation using the `#{<expr>}` character sequence, where <expr> is an FQL expression:

``"Alice is #{3 + 2} years old."``
``"Alice is 5 years old."``

See the escaped characters section for a list of escaped characters.

### Heredoc string

A heredoc String is a way to write a string that spans multiple lines, enclosing the string with a beginning and ending user-defined token:

``````<<+TOKEN
A multiline string
whitespaces
TOKEN``````
``````<<-END
A multiline string
whitespaces
END``````

The token, on a line by itself, terminates the String.

On rendering, whitespace is removed from form each line, maintaining the same relative indentation for each line.

Heredoc strings support interpolation:

``````let weather = "overcast with occasional showers"
<<+EOS
Hello.
Today is #{weather}
EOS``````
``````<<-END
Hello.
Today is overcast with occasional showers
END``````

To declare a String with variables but without doing interpolation, precede the String with a token in the format `<<-TOKEN`:

``````<<-ASIS
str => "Hello #{str}"
ASIS``````
``````<<-END
str => "Hello #{str}"
END``````

You might want to avoid interpolation when defining a Function body, for example. The `#{str}` variable executes in the context of the function instead of when the string is rendered.

## Array

Arrays group items and are represented as a comma-separated list of literals or expressions enclosed by `[ ]`:

``["a", 1 + 1, if (true) "true" else "false", null]``
``````[
"a",
2,
"true",
null
]``````

Array members can be accessed individually using a single variable. Members are indexed left to right, starting with 0. In the example, the `"a"` member is array element 0 and the `null` member is array element 3:

``````let array = ["a", 1 + 1, if (true) "true" else "false", null]
[ array[0], array[3]]``````
``````[
"a",
null
]``````

## Object

An Object is represented as a key:value pair enclosed by `{ }`, or field:value pair when referring to schema entities.

``{ "a": 1 }``

An object can hold multiple, comma-separated key:value pairs:

``````{
"a": 1,
b: 2
}``````

Key or field names can be identifiers or String literals:

## Anonymous function

An anonymous function is represented using the short-form, JavaScript-like arrow function syntax:

([parameter[, parameter]]) => {[statement [statement …​ ]] expression [expression …​ ]}

Or, simplified:

(parameter) => { expression }

If the function has only one parameter, `()` can be omitted around the parameter.

If the function body has only a single expression, the `{}` block delimiter can be omitted.

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com