Before start this article, let’s know little bit about operator.
What is operator ?
Operator is special type of symbol that is used to perform calculate on values and variables.
|+||Addition||x + y|
|–||Subtraction||x – y|
|*||Multiplication||x * y|
|/||Division||x / y|
|%||Remainder||x % y|
|++||Increment||x ++, ++x|
|—||Decrement||x –, –x|
|**||Exponentiation||x ** y|
Arithmetic operation operates on two numbers and those two numbers can be literals and variables.
Operators and Operands
The numbers are called operands and operation is defined by operator.
Let’s take simple example to understand operands and operator.
100 + 20
In above table 100 and 20 are operands, + is the operator.
The addition operator ( + ) is used to add numbers.
var result = 100 + 50; console.log(result)
The Subtraction operator ( – ) is used to subtract one number from other numbers.
var result = 100 - 50; console.log(result)
The Multiplication operator ( * ) is sued to multiply one or more values.
var result = 100 * 50; console.log(result)
The Dividing operator ( / ) is used to divide the numbers.
var result = 100 / 50; console.log(result)
The modulus operator ( % ) is used to return the division remainder.
var result = 109 / 50; console.log(result)
Increment operator ( ++ ) is used to increment the numbers.
var x = 10; x++ console.log(x)
Decrement operator ( – – ) is used to decrement the numbers.
var x = 10; x-- console.log(x)
The exponentiation operator (**) raises the first operand to the power of the second operand.
var x = 10; console.log(x ** 2);
Arithmetic operators are always used to perform arithmetic operations on operands. Operands can be values and variables.
Reference:- Click Here