Operators

Operators allow you to assign values to variables, compare values, and define conditional statements. Arcade supports the following operators.

Arithmetic operators

Arithmetic operators are used to perform arithmetic on numbers. See Type casting - Arithmetic statements to learn the casting behavior if either operand is not a number.

OperatorNameDescriptionExample
+AdditionAdds two numbers. Can also concatenate two text values.5+5
-SubtractionSubtracts two numbers.5-5
*MultiplicationMultiplies two numbers.5*5
/DivisionDivides two numbers.5/5
%ModulusReturns the remainder of a number divided by another number.10 % 2
++Increment by oneIncrements a number variable by one.x++ or ++x
--Decrement by oneDecrements a number variable by one.--x or x--

The increment/decrement by one operators have pre and post versions that differ in what they return. The pre increment version adds one to the variable and returns the new value while the post increment adds one and then returns the initial value of the variable.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
// Pre increment example
var x = 10;
++x  // x is now 11 and the value 11 is returned

// Post increment example
var x = 10;
x++ // x is now 11 but the value of 10 is returned.

Assignment operators

Assignment operators are used to assign values to variables. See Type casting - Assignment statements to learn the implicit casting behaviors during variable assignment.

OperatorNameDescriptionExample
=EqualsAssigns a value to a variable.x = 10
+=Add assignAdds a number to the value of a number variable and assigns the result to the variable.x += 10
-=Minus assignSubtracts a number from a value of a number variable and assigns the result to the variable.x -= 10
*=Multiply assignMultiplies a number by the value of a number variable and assigns the result to the variable.x *= 10
/=Divide assignDivides the value of a number variable by another number and assigns the result to the variable.x /= 2
Use dark colors for code blocksCopy
1
2
3
// Add assign
var x = 10;
x+=5  // x is now 15

Comparison operators

Comparison operators compare the values of two numbers. See Type casting - Comparison statements to learn the casting behavior of either operand.

OperatorNameDescriptionExample
==Equal toEvaluates to true if the x-value is equal to the y-value.x==y
!=Not equal toEvaluates to true if the x-value is not equal to the y-value.x!=y
>Greater thanEvaluates to true if the x-value is greater than the y-value.x>y
>=Greater than or equalEvaluates to true if the x-value is greater than or equal to the y-value.x>=y
<Less thanEvaluates to true if the x-value is less than the y-value.x<y
<=Less than equal toEvaluates to true if the x-value is less than or equal to the y-value.x<=y

Comparison operators attempt to coerce text to a number when comparing a text value to a number. The == and != operators don't do any coercion of types. If the types are different, then they are not equal.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
10 == "10"  // returns false
10 != "10"  // returns true
10 > "10"   // returns false
10 >= "10"  // returns true
10 < "10"   // returns false
10 <= "10"  // returns true
9  < "10"   // returns true
11 < "10"   // returns false

For arrays, dictionaries, and geometry types, comparisons are a pointer check to see if they are the same object. Internal values of the object are not checked.

Use dark colors for code blocksCopy
1
2
3
4
var a1 = [1,2,3]
var a2 = [1,2,3]
a1 == a2  // evaluates to false since they are not the same object.
a1 == a1  // evaluates to true since they are the same object.

Comparing DateOnly or Date values with Time values will throw an error.

Logical operators

Logical operators specify whether two conditions should be grouped together or evaluated separately. See Type casting - Logical statements to learn the casting behavior if either operand is not a boolean.

OperatorNameDescriptionExample
| |Logical orReturns true if one of two statements evaluates to true.if (x==9 || y==0)
&&Logical andReturns true if both statements evaluate to true.if (x==9 && y==0){}
!Logical notReturns true if the statement does not return true.if(!didItWork) { console("No. It didn't work.") }
Use dark colors for code blocksCopy
1
2
3
if(!IsEmpty($feature.MyField)){
  return "This field has a value";
}

Unary operators

Unary operators indicate if a value is positive or negative. See Type casting - Unary statements to learn the casting behavior if either operand is not a number.

OperatorDescriptionExample
+Returns the value.+10
-Negates the value.-10

Bitwise operators

Since 1.11

Bit operators work with 32 bit numbers.

OperatorNameDescriptionExample
&Bitwise ANDReturns a 1 in each bit position for which the corresponding bits of both operands are 1s. If either bit of one of the operands is 0, the corresponding bit of the result is also 0.a & b
|Bitwise ORReturns a 1 in each bit position for which the corresponding bits of either or both operands are 1s.a | b
^Bitwise XORReturns a 1 in each bit position for which the corresponding bits of either but not both operands are 1s.a ^ b
~Bitwise NOTInverts the bits of its operand. Bits that are 0 become 1 and bits that are 1 become 0. Bitwise NOTing any number x yields -(x+1)~ a
<<Left shiftShifts a in binary representation b (< 32) bits to the left, shifting in 0s from the right.a << b
>>Sign propagating right shiftShifts a in binary representation b (< 32) bits to the right, discarding bits shifted off, and shifting in copies of the leftmost bit from the left.a >> b
>>>Zero fill right shiftShifts a in binary representation b (< 32) bits to the right, discarding bits shifted off, and shifting in 0s from the left. The sign bit becomes 0, so the result is always non-negative.a >>> b

Bitwise operators will perform their operation on the binary representation of the number provided to the operator, and will return a standard numerical value.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
7 & 14
// converts to 0111 and 1110
// result is 0110, which returns 6

7 | 14
// result is 1111, which returns 15

7 ^ 14
// result is 1001, which returns 9

~ 7
// converts to 00000000000000000000000000000111
// result is 11111111111111111111111111111000 (inverted operand)
// returns -8

7 << 2
// shift 00000000000000000000000000000111 two bits to the left
// result is 00000000000000000000000000011100
// returns 28

7 >> 2
// shift 00000000000000000000000000000111 two bits to the right
// result is 000000000000000000000000000001
// returns 1

-7 >> 2
// shift 11111111111111111111111111111001 two bits to the right
// result is 11111111111111111111111111111110
// returns -2

-7 >>> 2
// shift 11111111111111111111111111111001 two bits to the right
// result is 00111111111111111111111111111110
// returns 1073741822

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.