# 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.

Operator | Name | Description | Example |
---|---|---|---|

+ | Addition | Adds two numbers. Can also concatenate two text values. | `5+5` |

- | Subtraction | Subtracts two numbers. | `5-5` |

* | Multiplication | Multiplies two numbers. | `5*5` |

/ | Division | Divides two numbers. | `5/5` |

% | Modulus | Returns the remainder of a number divided by another number. | `10 % 2` |

++ | Increment by one | Increments a number variable by one. | `x++` or `++x` |

-- | Decrement by one | Decrements 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.

## 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.

Operator | Name | Description | Example |
---|---|---|---|

= | Equals | Assigns a value to a variable. | `x = 10` |

+= | Add assign | Adds a number to the value of a number variable and assigns the result to the variable. | `x += 10` |

-= | Minus assign | Subtracts a number from a value of a number variable and assigns the result to the variable. | `x -= 10` |

*= | Multiply assign | Multiplies a number by the value of a number variable and assigns the result to the variable. | `x *= 10` |

/= | Divide assign | Divides the value of a number variable by another number and assigns the result to the variable. | `x /= 2` |

## Comparison operators

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

Operator | Name | Description | Example |
---|---|---|---|

== | Equal to | Evaluates to true if the x-value is equal to the y-value. | `x==y` |

!= | Not equal to | Evaluates to true if the x-value is not equal to the y-value. | `x!=y` |

> | Greater than | Evaluates to true if the x-value is greater than the y-value. | `x>` |

>= | Greater than or equal | Evaluates to true if the x-value is greater than or equal to the y-value. | `x>` |

< | Less than | Evaluates to true if the x-value is less than the y-value. | `x<` |

<= | Less than equal to | Evaluates to true if the x-value is less than or equal to the y-value. | `x<` |

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.

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.

## 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.

Operator | Name | Description | Example |
---|---|---|---|

| | | Logical or | Returns `true` if one of two statements evaluates to `true` . | `if (x==9 || y==0){}` |

&& | Logical and | Returns `true` if both statements evaluate to `true` . | `if (x==9 && y==0){}` |

! | Logical not | Returns `true` if the statement does not return `true` . | `if(!did` |

## 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.

Operator | Description | Example |
---|---|---|

+ | Returns the value. | +10 |

- | Negates the value. | -10 |

## Bitwise operators

Bit operators work with 32 bit numbers.

Operator | Name | Description | Example |
---|---|---|---|

& | Bitwise AND | Returns a `1` in each bit position for which the corresponding bits of both operands are `1` s. If either bit of one of the operands is `0` , the corresponding bit of the result is also `0` . | `a & b` |

| | Bitwise OR | Returns a `1` in each bit position for which the corresponding bits of either or both operands are `1` s. | `a | b` |

^ | Bitwise XOR | Returns a `1` in each bit position for which the corresponding bits of either but not both operands are `1` s. | `a ^ b` |

~ | Bitwise NOT | Inverts 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 shift | Shifts `a` in binary representation `b` (< 32) bits to the left, shifting in `0` s from the right. | `a <` |

>> | Sign propagating right shift | Shifts `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 >` |

>>> | Zero fill right shift | Shifts `a` in binary representation `b` (< 32) bits to the right, discarding bits shifted off, and shifting in `0` s from the left. The sign bit becomes `0` , so the result is always non-negative. | `a >` |

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