Precedence and Associativity

The associativity represents which operator has to solve first while going from left to right if two or more operators have the same precedence in the expression.

Example:

2 + 3 * 4 / 3 =  2 + (3 * 4) / 3  // 6

The precedence of the multiply(*) and divide(/) operators is the same but due to associativity from left to right the multiply operator will be resolved first as it comes first when we go from left to right and hence the result will be 6.

Operator precedence in JavaScript

Operator precedence refers to the priority given to operators while parsing a statement that has more than one operator performing operations in it. Operators with higher priorities are resolved first. But as one goes down the list, the priority decreases and hence their resolution.

( * ) and ( / ) have higher precedence than ( + ) and ( - )

Similar Reads

Precedence and Associativity

The associativity represents which operator has to solve first while going from left to right if two or more operators have the same precedence in the expression....

Operator Precedence and Associativity Table

The operator precedence and associativity table can help one know the precedence of an operator relative to other operators. As one goes down the table, the precedence of these operators decreases over each other. The operators as subparts of precedence will have the same specified precedence and associativity as contained by the main part....