Javascript Mathematical Operators
Given that y=5
| Operator | Description | Example | Result |
| + | Addition | x=y+2 | x=7 |
| - | Subtraction | x=y-2 | x=3 |
| * | Multiplication | x=y*2 | x=10 |
| / | Division | x=y/2 | x=2.5 |
| % | Modulus(division remainder) | x=y%2 | x=1 |
| ++ | Increment | x=++y | x=6 |
| -- | Decrement | x=--y | x=4 |
| - | Negation | x=-y | X=-5 |
In a compound equation like the one assigned to longEquation, each of the operations is subject to standard mathematical precedence (that is, multiplication and division operations are calculated first, from left to right, after which the addition and subtraction operations are calculated from left to right).
If you want to override the standard precedence of these operations, you can use brackets, just like you learned in school. Any operations that occur inside brackets will be calculated before any multiplication or division is done:
var bracketed = (4 + 6) * 5;
Here, the value of unbracketed will be 34, because 6 * 5 is calculated first. The value of bracketed will be 50, because (4 + 6) is calculated first.