Skip to content

Logical operators#

CEL provides operators for boolean logic.

Not#

The ! operator negates a boolean value.

!false
// result: true (bool)
!true
// result: false (bool)

And#

The && operator returns true if both operands are true.

true && true
// result: true (bool)
true && false
// result: false (bool)

Or#

The || operator returns true if either operand is true.

false || true
// result: true (bool)
false || false
// result: false (bool)

Short-circuit evaluation#

CEL evaluates && and || left to right and stops as soon as the result is determined.

// input: x = 0
x != 0 && 10 / x > 1
// result: false (bool)

The division is never evaluated because x != 0 is false. This prevents a division-by-zero error.

// input: x = 0
true || 10 / x > 1
// result: true (bool)

The division is never evaluated because the left side is already true.

Operator precedence#

The && operator has higher precedence than ||.

true || false && false
// result: true (bool)
(true || false) && false
// result: false (bool)

See also#