Associativity comes in to the picture when we have same operators in an expression. It tells the order of evaluation that which operator should work first.
operators are left associative
(executes from left to right).
4 + 3 + 2
In the above example, first the sum is performed between 4 and 3. Then the result will be summed to 2.
and null coalescing
operators are right associative
(executes from right to left).
x = y = z = 6
In the above example, 6 is first assigned to z
and then to y
and so on.
Asked In: Spotted While Learning |