Operators

Every operator supported by the expr evaluator, organised by arity. Click any entry in the sidebar to jump directly to its reference — you stay on this page throughout.

Unary

Unary Operators

Operate on a single operand placed either before or after it. They transform or interrogate one value without needing a second.

-x
Unary

Negation

Reverses the sign of a numeric value. Applied as a prefix, it multiplies the operand by −1. Works on integers, floats and the result of any sub-expression enclosed in parentheses.

x-x
5-5
-3.143.14
0-0
-(-(47))47
Example
-(5 + 3)     → -8
-(-12)       → 12
-(2 ** 4)    → -16
+x
Unary

Unary Plus

Attempts to convert the operand to a number. If the operand is already a number it returns it unchanged — no sign flip occurs. Unlike negation, its sole purpose is numeric coercion.

x+x
55
+(-(11))-11
Example
+5        → 5
+(-(11))  → -11
!x
Unary

Logical NOT

Inverts a boolean value. Returns false if the operand is truthy, true if it is falsy. Logical not unary operator supports use with parentheses.

x!x
truefalse
falsetrue
Example
!true        → false
!false       → true
!!false      → false
!!true       → true
!(!true)     → true
!((!true))   → true
Binary — Arithmetic

Arithmetic Operators

Work on two numeric operands to produce a computed result. Precedence order (high → low): **, then * / %, then + -. Use parentheses to override.

+
Binary Arithmetic

Addition

Adds two numeric operands together. If either operand is a string, concatenation is performed instead. For pure math expressions, both operands should evaluate to numbers.

ABA + B
358
10-46
2.51.54
Example
(100 + 200) * 3    → 900
1.1 + 2.2          → 3.3
0 + 0              → 0
Binary Arithmetic

Subtraction

Subtracts the right operand from the left, returning their arithmetic difference. Unlike the unary -, this always requires two operands placed on either side of the operator.

ABA - B
1046
37-4
8.52.56
Example
1000 - 375 - 125   → 500
(10 - 3) * 2       → 14
*
Binary Arithmetic

Multiplication

Returns the product of two operands. Evaluated before addition and subtraction following standard operator precedence. Use parentheses to override evaluation order.

ABA * B
3412
-25-10
1.523
Example
(2 + 3) * (4 - 1)   → 15
4 * 0.25            → 1
-3 * -3             → 9
/
Binary Arithmetic

Division

Divides the left operand by the right, returning a floating-point result — it never rounds automatically. Dividing by zero yields no value; dividing zero by zero yields in indeterminate value.

ABA / B
1025
723.5
10Infinity
Example
360 / (2 * 6)   → 30
1 / 3           → 0.3333333333333333
5 / 0           → No value
%
Binary Arithmetic

Modulo / Remainder

Returns the remainder after dividing the left operand by the right. The sign of the result always matches the sign of the left (dividend) operand. Useful for divisibility checks and cyclic indexing.

ABA % B
1031
770
-94-1
Example
17 % 5     → 2    // remainder of 17 ÷ 5
100 % 2    → 0    // even-number check
13 % 4     → 1
**coming soon
Binary Arithmetic

Exponentiation

Raises the left operand (base) to the power of the right operand (exponent). Right-associative: 2 ** 3 ** 2 evaluates as 2 ** 9 = 512, not 8 ** 2. Fractional exponents compute roots.

baseexpbase ** exp
2101024
3327
90.53
Example
2 ** 8         → 256
9 ** 0.5       → 3     // √9
2 ** 3 ** 2    → 512   // right-associative: 2 ** 9
Binary — Comparison

Comparison Operators

Compare two values and return a boolean — true or false. Results can be used directly or chained with logical operators for compound conditions.

===coming soon
Binary Comparison

Strict Equality

Returns true if both operands have the same value and the same type — no type coercion is performed. Prefer === over == to avoid subtle bugs from implicit conversions.

ABA === B
55true
5"5"false
true1false
nullnulltrue
Example
5 === 5       → true
5 === "5"     → false   // different types — no coercion
1 === true    → false
!==coming soon
Binary Comparison

Strict Inequality

The inverse of ===. Returns true if the operands differ in value or in type. No type coercion is performed. Prefer !== over != for predictable comparisons.

ABA !== B
53true
5"5"true
77false
Example
10 !== "10"   → true    // type mismatch
10 !== 10     → false
10 !== 11     → true
<
Binary Comparison

Less Than

Returns true if the left operand is strictly less than the right.

ABA < B
35true
82false
44false
Example
3 < 5    → true
5 < 5    → false   // equal, not less
-1 < 0   → true
>
Binary Comparison

Greater Than

Returns true if the left operand is strictly greater than the right.

ABA > B
53true
28false
44false
Example
5 > 3       → true
100 > 100   → false   // equal, not greater
-1 > -10    → true
<=
Binary Comparison

Less Than or Equal

Returns true if the left operand is less than or equal to the right.

ABA <= B
35true
55true
82false
Example
5 <= 10    → true
10 <= 10   → true    // equal counts
11 <= 10   → false
>=
Binary Comparison

Greater Than or Equal

Returns true if the left operand is greater than or equal to the right.

ABA >= B
105true
55true
38false
Example
score >= 90    → true   // if score is 95
18 >= 18       → true   // equal counts
17 >= 18       → false
Binary — Logical

Logical Operators

Combine or modify boolean expressions. All three short-circuit: evaluation stops as soon as the outcome is determined, without evaluating the remaining operand.

&&
Binary Logical

Logical AND

Returns true only when both operands are truthy. Short-circuits: if the left operand is falsy, the right is never evaluated. In non-boolean contexts, returns the first falsy value found, or the last value if all are truthy.

ABA && B
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse
Example
true && true      → true
true && false     → false
5 > 3 && 2 < 4   → true    // both hold
||
Binary Logical

Logical OR

Returns true if at least one operand is truthy. Short-circuits: if the left is truthy, the right is not evaluated. Returns the first truthy value found, or the last value if all are falsy.

ABA || B
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse
Example
true || false     → true
false || false    → false
0 || 42           → 42        // first truthy
??coming soon
Binary Logical

Nullish Coalescing

Returns the right operand only when the left is null or undefined. Unlike ||, it does not treat 0, "", or false as nullish — making it the safer choice for default values when those are legitimate inputs.

LeftRightLeft ?? Right
null"default""default"
undefined4242
0"fallback"0
"""fallback"""
falsetruefalse
Example
null ?? "default"      → "default"
undefined ?? 0         → 0
0 ?? "fallback"        → 0     // 0 is not null/undefined
"" ?? "empty"          → ""    // "" is not null/undefined
Ternary

Ternary Operator

JavaScript's only operator that takes three operands. Provides a concise inline alternative to an if / else statement.

? :
Ternary

Conditional

Syntax: condition ? valueIfTrue : valueIfFalse. Evaluates the condition; if truthy returns the first branch, otherwise returns the second. Can be nested for multi-branch logic, though deep nesting hurts readability — prefer a lookup object instead.

conditionResult returned
truevalueIfTrue
falsevalueIfFalse
Example
score >= 90 ? "A" : "B"             // "A" if score ≥ 90
x > 0 ? "positive" : "non-positive"
age >= 18 ? "green" : "blue"
n % 2 === 0 ? "even" : "odd"