The order of operation when multiple operators are used in combination is defined by two mechanisms: precedence and associativity. An operator's precedence is a number from 1 to 20, and defines the order in which a series of operators will run. Some operators share the same precedence. Associativity defines the order in which operators of the same precedence will be operated on (either left-to-right or right-to-left).
Consider the following operation:
1 + 2 * 3 / 4 - 5;
In JavaScript, these specific mathematic operators have the following precedences:
- The addition operator (+) has a precedence of 13
- The multiplication operator (*) has a precedence of 14
- The division operator (/) has a precedence of ...