- An arithmetic operator is comprised of many mathematical functions to do the math stuff.
- Arithmetic Operators are ( +, -, *, /, --, %, ++ ) , we will see one by one with a perfect code example to understand what is happening in a code while using arithmetic operators.
1. + (Addition)
The + is an operator that performs the additional math function using the operands/value we assign in a variable.
let num1 = 400; let num2 = 500; let sum = num1+num2; console.log(sum)
2. - (Subtraction)
The - is an operator which performs the subtraction math function using some of the operands/values we assign in a variable same as the + function.
let num1 = 400; let num2 = 500; let diff = num2 - num1; console.log(diff)
3. * (Multiplication)
The * is an operator which performs the multiplication math function using the operands we assign.
let num1 = 4; let num2 = 5; let mul = num1 * num 2; console.log(mul)
4. / (Division)
The / operator divides the assigned operand/value.
let num1 = 20; let num2 = 5; let div = num1 / num2; console.log(div)
5. % (Modulus)
The modulus operator % divides the provided value and gives out the remainder/leftover.
let num1 = 10; let mod = num1 % 3; console.log(mod)
6. ++ (Increment)
The ++ or increment operator increments/increase the provided value within a variable when initiated after the declaration.
let neoSalary = 20000; neoSalary++ console.log(neoSalary)
7. -- (Decrement)
The -- or decrement operator decrements/decrease the provided value within a variable when initiated after the declaration.
let neoSalary = 20000; neoSalary-- console.log(neoSalary)