Explain about the Arithmetic operator with suitable example.
Advertisements
Question
Explain about the Arithmetic operator with suitable example.
Long Answer
Advertisements
Solution
JavaScript supports all the basic arithmetic operators like addition (+), subtraction (–), multiplication (*), division (/), and modulus (%, also known as the remainder operator).
Arithmetic Operators:
| Arithmetic Operator | Meaning | Example | Result |
| + | Addition | var sum = 20 + 120 | Variable sum = 140 |
| - | Subtraction | var diff = 20 - 120 | Variable diff = 100 |
| * | Multiplication | var prod = 10 * 100 | Variable prod = 1000 |
| / | Division | var res = 100/522 | Variable res = 5.22 |
| % | Modulus operator | var rem = 100 % 522 | Variable rem = 22 (remainder) |
HTML CODE Using Arithmetic Operators:
<Html>
<Head>
<Title>Demo Program – To test Arithmetic Operators in JavaScript
</Title>
</Head>
<Body>
<script language="javascript" type="text/javascript">
var value1 = 522, value2=10;
document.write("<br>Data1 : "+value1);
document.write("<br>Data2 : "+value2);
var sum = value1+value2;
var diff = value1-value2;
var prod = value1*value2;
var res = value1/value2;
var rem = value1%value2;
document.write("<br><br>The Sum of Data1 and Data2 : "+sum);
document.write("<br>The Difference of Data1 and Data2 : "+diff);
document.write("<br>The Product of Data1 and Data2 : "+prod);
document.write("<br>The Result after Division of Data1 and Data2 : "+res);
document.write("<br>The Remainder after Division of Data1 and Data2 :
"+rem);
</script>
</Body>
</Html>
Output:

shaalaa.com
Javascript Operators and Expressions
Is there an error in this question or solution?
