- Arithmetic Operators: (+, -, *, /,%, **)
- Comparison Operators or Operators to Compare Two or More Values: – (==,! =, ===,! ==, <,>, <=,> =)
- Incrementing / Decrementing Operators or 1 Increase or Decrease Operator: – (++, – -)
- Logical Operators or Operators for making decisions based on multiple conditions: – (&&, ||,!)
- String Operators or Operators for pairing with one or more string: – (+)
- Ternery Operator or if..else Operator.
- delete Operator: or delete operator is used to delete a specific property of an object.
- in Operator: Used to find the specific property of the object.
Here the two sides of the plus sign (+) are a and 5 respectively. These two operands and the plus sign (+) are the operators.
What is Operator Precedence?
Explanation: The result of the above code will not be 18 but 16. The main reason for this is that among the two operators we use here, according to the Operator Precedence Rules, the multiplication (“*”) operator is given more priority than the addition (“+”) operator. Let’s look at another example below:
Explanation: Since the Parentheses “()” operator is given more priority than the Multiplication “*” operator in the above example, the work of addition between the parentheses is performed first. Then the function of multiplication “*” is performed.
What is Operator Associativity?
- Right to Left (ie: Right Operator will be preferred.)
- Left to Right (ie: Left Operator will be preferred.)
|Operator||Operator Use||Operator Associativity||Operator Precedence|
|()||Method/function call, grouping||Left to right||Highest — 1|
|||Array access||Left to right||1|
|.||Object property access||Left to right||1|
|++||Increment||Right to left||2|
|—||Decrement||Right to left||2|
|–||Negation||Right to left||2|
|!||Logical NOT||Right to left||2|
|~||Bitwise NOT||Right to left||2|
|delete||Removes array value or object property||Right to left||2|
|new||Creates an object||Right to left||2|
|typeof||Returns data type||Right to left||2|
|void||Specifies no value to return||Right to left||2|
|/||Division||Left to right||3|
|*||Multiplication||Left to right||3|
|%||Modulus||Left to right||3|
|+||Plus||Left to right||4|
|+||String Concatenation||Left to right||4|
|–||Subtraction||Left to right||4|
|>>||Bitwise right-shift||Left to right||5|
|<<||Bitwise left-shift||Left to right||5|
|>, >=||Greater than, greater than or equal to||Left to right||6|
|<, <=||Less than, less than or equal to||Left to right||6|
|==||Equality||Left to right||7|
|!=||Inequality||Left to right||7|
|===||Identity operator — equal to (and same data type)||Left to right||7|
|!==||Non-identity operator — not equal to (or don’t have the same data type)||Left to right||7|
|&||Bitwise AND||Left to right||8|
|^||Bitwise XOR||Left to right||9|
||||Bitwise OR||Left to right||10|
|&&||Logical AND||Left to right||11|
|||||Logical OR||Left to right||12|
|?:||Conditional branch||Left to right||13|
|=||Assignment||Right to left||14|
|*=, /=, %=, +=,, -=, <<=, >>=, >>>=, &=, ^=, |=||Assignment according to the preceding operator||Right to left||14|
|,||Multiple evaluation||Left to right||Lowest: 15|