DEV Community

Mubasshir Ahmed
Mubasshir Ahmed

Posted on

Arithmetic Operator

Addition operator ( + ) Example : 10+10 = 20
Subtraction operator ( - ) Example : 22-10 = 12
Multiplication Operator ( * ) Example : 4*5 = 20
Division Operator ( / ) Example : 12/2 = 6
Remainder/Modulo operator ( % ) Example : 5%2 = 1
Exponent Operator ( ** ) Example : 5**2 = 25 (same as 5*5)

Application of arithmetic operator.

Find any digit from a number.
Suppose we have a number 53425. Print 3rd digit from this number.
Here we use the arithmetic operator.
53425 % 1000 = 425
425 / 100 = 4 ( 4 is the third digit of this number)

var res = Math.floor((n % 1000) / 100);
Enter fullscreen mode Exit fullscreen mode

another example :
Print 3rd and 4th number digit from 53425.
53425 % 1000 = 425
425 / 10 = 42 ( Here 4 and 2 are the third and 4th digit of this number )

   var res = Math.floor((n % 1000) / 10);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)