Arithmetic Operators
JavaScript Arithmetic
Arithmetic operators are used to perform arithmetic between variables and/or values.
Given that y = 5, the table below explains the arithmetic operators:
Oper | Name / Link | Example | Results |
---|---|---|---|
+ | Addition | x = y + 2 | y=5, x=7 |
- | Subtraction | x = y - 2 | y=5, x=3 |
* | Multiplication | x=y*2 | y=5, x=10 |
/ | Division | x = y / 2 | y=5, x=2.5 |
** | Exponentiation | x = y ** 2 | y=5, x=25 |
% | Remainder | x = y % 2 | y=5, x=1 |
++ | Increment | x = y++ | y=6, x=5 |
++ | Increment | x = ++y | y=6, x=6 |
-- | Decrement | x = y-- | y=4, x=5 |
-- | Decrement | x = --y | y=4, x=4 |
+ | Unary Plus | x= +y | x=5 |
- | Unary Negation | x= -y | x=-5 |
Learn More:
Study our JavaScript Arithmetic Tutorial.