An arithmetic operator accepts numerical values as operands and returns a single numerical value. The numerical values can be literals or variables.
In JavaScript following are the arithmetic operators :
A typical arithmetic operation operates on two numbers, which can be literals, variables or expressions.
These numbers in an arithmetic operation are called operands. And the operation that needs to be performed between the two operands is defined by an operator
Let us discuss the arithmetic operators with example.
Addition: The addition operator
+
adds numbers.Subtraction: The subtraction operator
-
subtracts numbers.
- Multiplication: The multiplication operator
*
multiplies numbers.
- Division: The division operator
/
divides numbers.
- Modulus: The modulus operator
%
returns the division remainder.
- Exponentiation: The exponentiation operator
**
raises the first operand to the power of the second operand.
- Increment: The increment operator
++
increments numbers.
- Decrement: The decrement operator
--
decrements numbers.
While doing operations of expressions in JavaScript, the focus should be given to Operator Precedence.
Operator precedence describes the order in which operations are performed in an arithmetic expression.
When using parentheses, the operations inside the parentheses are computed first.
Multiplication
*
and division/
have higher precedence than addition+
and subtraction-
.When many operations have the same precedence (like addition and subtraction or multiplication and division), they are computed from left to right.
Click for Operator Precedence Table
In the next blog, we will discuss Basic Math in JavaScript.
If you liked this article, consider following me on Hashnode for my latest publications.