Arithmetic operators are used to perform arithmetic operations on the operands. The following operators are known as JavaScript arithmetic operators.
Operator | Description | Example |
---|---|---|
+ | Addition | 10+20 = 30 |
- | Subtraction | 20-10 = 10 |
* | Multiplication | 10*20 = 200 |
/ | Division | 20/10 = 2 |
% | Modulus (Remainder) | 20%10 = 0 |
++ | Increment | var a=10; a++; Now a = 11 |
-- | Decrement | var a=10; a--; Now a = 9 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JavaScript</title>
<script>
/* Addition Arithmetic Operators */
var a = 10;
var b = 10;
var c = a + b;
document.write(c);
document.write("<br><br>");
/* Subtraction Arithmetic Operators */
var m = 10;
var n = 5;
var o = m - n;
document.write(o);
document.write("<br><br>");
/* Multiplication Arithmetic Operators */
var p = 10;
var q = 10;
var r = a * b;
document.write(r);
document.write("<br><br>");
/* Exponentiation Arithmetic Operators */
var d = 10;
var e = 3;
var f = d ** e;
document.write(f);
document.write("<br><br>");
/* Division Arithmetic Operators */
var s = 14;
var t = 2;
var w = s / t;
document.write(w);
document.write("<br><br>");
/* Modulus(Remainder) Arithmetic Operators */
var x = 14;
var y = 2;
var z = a % b;
document.write(z);
document.write("<br><br>");
/* Increment Arithmetic Operators */
var i = 10;
var j = 3;
document.write(i + j);
document.write("<br>");
i++;
document.write(i + j);
document.write("<br><br>");
/* Decrement Arithmetic Operators */
var g = 10;
var h = 3;
document.write(g + h);
document.write("<br>");
g--;
document.write(g + h);
</script>
</head>
<body>
</body>
</html>