Example
var total_price = ticket_price * number_of_tickets
The characters =
and *
are operators. ticket_price
and number_of_tickets
are operands of the multiplication, and total_price
is the left operand of the assignment.
Multiplying has the highest precedence; otherwise the assignment would not make sense. You can view all operators and their precedence in the following table.
List of all available operators
Binary Operator
|
Precedence |
Description |
---|---|---|
=
|
1 | Assign a value to a variable |
+=
|
1 | A shortcut for x = x + ... |
-= |
1 | A shortcut for x = x - ... |
*= |
1 | A shortcut for x = x * ... |
/=
|
1 | A shortcut for x = x / ... |
::= |
1 | A shortcut for x = x :: ... |
||
|
2 | Boolean operator that evaluates to true if and only if either of its operands are true |
&&
|
3 | Boolean operator that evaluates to true if and only if both of its operands are true |
==
|
4 | Boolean operator that evaluates to true if and only if both of its operands are equal |
!= |
4 | Boolean operator that evaluates to false if and only if both of its operands are equal |
>
|
5 | Boolean operator that evaluates to true if and only if the number value of the left operand is greater than the number value of the right operand |
<
|
5 | Boolean operator that evaluates to true if and only if the number value of the left operand is less than the number value of the right operand |
>=
|
5 | Boolean operator that evaluates to true if and only if the number value of the left operand is greater than or equal to the number value of the right operand |
<=
|
5 | Boolean operator that evaluates to true if and only if the number value of the left operand is less than or equal to the number value of the right operand |
+ |
6 | Arithmetic addition of the number values of the two operands |
- |
6 | Arithmetic subtraction of the number values of the two operands |
:: |
6 | Concatenation of the string values of the two operands |
* |
7 | Arithmetic multiplication of the number values of the two operands |
/ |
7 | Arithmetic division of the number values of the two operands |
% |
7 | Modulo operation with the left operand as the dividend and the right operand as the divider |
^ |
7 | Exponential operation with the left operand as the base and the right operand as the exponent |
Unary Operator | Precedence | |
!
|
8 | Negation operator that evaluates to true if the operand is false |
--x |
8 | Decrement x by 1 and return (x - 1) |
x-- |
8 | Decrement x by 1 and return original value of x |
++x |
8 | Increment x by 1 and return (x + 1) |
x++ |
8 | Increment x by 1 and return original value of x |
@x
|
8 | Mark variable x as a String constant. This will prevent all number operations on this expression. |