JS Associativity of Operators
In this article, we will see the associativity of operators in js.
Associativity of operators
If the same operator appears one or more times in an expression, in which direction the specific operator needs to be evaluated is determined by the associativity of operators.
While evaluating any given expression if operators appear multiple times whether that operator should be evaluated from left to right or from right to left is determined by the associativity operator.
var result = 3 * 5 + 4 / 2 + 3 + 20 -10
var result = 2 + 2 + 4 + 2; var a = b = c = 10;
Here we have an assignment operator which is appearing three times and it has right to left associative, so we have to evaluate it from right to left. 10 is assigned to c, c is assigned to b, b is assigned to a.