What are JavaScript Arithmetic Operators?

 


   

x = 20; y = 5;

result
+ Additon

result = x + y

25
- Subtraction

result = x - y

15
* Multiplication

result = x * y;

100
/ Divide result = x / y; 4
% Mode Retrieval result = y % x; 0
++ Increase sonuc = x++; 21
-- Decrease result = x--; 19
** Exponentiation result = 2 ** 3; 8


Additon Operator (+)

var x = 100 + 50;

The numbers one hundred and 50 are brought consistent with the addition operator and the result is transferred into the variable x on the left.


Subtraction Operator (-)


var a = 5;
var x = (100 + 50) - a;

After 100 + 50 in parentheses, variable a is subtracted from 150 and the result is 145.


Multiplication Operator (*)


var x = 5;
var y = 3;
var z = (x + y) * (y - x);

The value of (x+y) in parentheses is multiplied by 8 and the fee of (y-x) is -2 and the result is set to variable z as -16.


Divide Operator (/)


var x = 5;
var y = 2;
var z = (x * y) / y;

The fee of (x*y) in parentheses is split through 10, which is the value of y, and the end result is transferred as five to the variable z.


Mode Retrieval Operator; (%)


var x = 1001;
var y = 2;
var z = x % y;

The quantity received by means of dividing the number 1001, that is the value of the variable x, via 2 with out a remainder is 1.


Increase Operator (++)


x = 10;
y = x++;

We boom the fee of the x's variable by 1 and set it to the variable y. You can do similar to underneath.


x = 10; 
y = x + 1;

Decrease Operator (--)


x = 10;
y = x--;

We reduce the value of the variable x's by using 1 and set it to the variable y. You can do the same as beneath.


x = 10; 
y = x - 1;

Exponentiation Operator (**)


var x = 5;
var z = x ** 2;    

We get the electricity of 5, which is the value of the variable x, with the wide variety 2. Therefore, multiplying 5 by using 2 instances gives the result 25.

*

Post a Comment (0)
Previous Post Next Post

Iklan Tengan Artikel 1