Introduction
The operations performed on one or more operands are represented by a token or symbol known as an operator. However, every programming language has its own set of operators used to perform multiple operations on the operands.
Operands are expressions, and operators further help to convert these expressions into larger ones. For example, if we take the numeric literal 7 and an operator *, it can be combined into an expression like 7*7. Similarly, the expression below combines a numeric literal, a method invocation expression, and a variable reference expression with the multiplication and greater-than operator.
7 * Math.sqrt(7) > limit
where 7 is a numeric literal and Math.sqrt(7) is a method invocation. We will further discuss the working of operators in detail.
Some Important Terms
Some important terms related to operators are-
1. Arity- The number of operands upon which an operator can work is called its arity. The unary operator works on only a single operand. The binary operator operates on two operands; the ternary operator works on three operands, etc.
2. Precedence- The bonding of an operator with its operands. It tells which operation is performed first and which next.
Example:
2 + 3 * 4 # => 14
In this example, we see multiplication has higher precedence than addition; hence it is performed first.
3. Associativity- If the same operator occurs multiple times in an expression and sequentially, it defines the expression's order of evaluation.
The table below describes all the operators according to their precedence from top to bottom and further shows the same's arity, associativity, and operation.