# Bicep operators

This article describes the Bicep operators. Operators are used to calculate values, compare values, or evaluate conditions. There are four types of Bicep operators:

## Operator precedence and associativity

The operators below are listed in descending order of precedence (the higher the position the higher the precedence). Operators listed at the same level have equal precedence.

Symbol Type of Operation Associativity
`(` `)` `[` `]` `.` `::` Parentheses, array indexers, property accessors, and nested resource accessor Left to right
`!` `-` Unary Right to left
`%` `*` `/` Multiplicative Left to right
`+` `-` Additive Left to right
`<=` `<` `>` `>=` Relational Left to right
`==` `!=` `=~` `!~` Equality Left to right
`&&` Logical AND Left to right
`||` Logical OR Left to right
`?` `:` Conditional expression (ternary) Right to left
`??` Coalesce Left to right

## Parentheses

Enclosing an expression between parentheses allows you to override the default Bicep operator precedence. For example, the expression `x + y / z` evaluates the division first and then the addition. However, the expression `(x + y) / z` evaluates the addition first and division second.

## Accessor

The accessor operators are used to access nested resources and properties on objects.

Operator Name Description
`[]` Index accessor Access an element of an array or property on an object.
`.` Function accessor Call a function on a resource.
`::` Nested resource accessor Access a nested resource from outside of the parent resource.
`.` Property accessor Access properties of an object.

## Comparison

The comparison operators compare values and return either `true` or `false`.

Operator Name Description
`>=` Greater than or equal Evaluates if the first value is greater than or equal to the second value.
`>` Greater than Evaluates if the first value is greater than the second value.
`<=` Less than or equal Evaluates if the first value is less than or equal to the second value.
`<` Less than Evaluates if the first value is less than the second value.
`==` Equals Evaluates if two values are equal.
`!=` Not equal Evaluates if two values are not equal.
`=~` Equal case-insensitive Ignores case to determine if two values are equal.
`!~` Not equal case-insensitive Ignores case to determine if two values are not equal.

## Logical

The logical operators evaluate boolean values, return non-null values, or evaluate a conditional expression.

Operator Name Description
`&&` And Returns `true` if all values are true.
`||` Or Returns `true` if either value is true.
`!` Not Negates a boolean value. Takes one operand.
`??` Coalesce Returns the first non-null value.
`?` `:` Conditional expression Evaluates a condition for true or false and returns a value.

## Numeric

The numeric operators use integers to do calculations and return integer values.

Operator Name Description
`*` Multiply Multiplies two integers.
`/` Divide Divides an integer by an integer.
`%` Modulo Divides an integer by an integer and returns the remainder.
`+` Add Adds two integers.
`-` Subtract Subtracts one integer from another integer. Takes two operands.
`-` Minus (unary) Multiplies an integer by `-1`. Takes one operand.

Note

Subtract and minus use the same operator. The functionality is different because subtract uses two operands and minus uses one operand.