JavaScript Arithmetic Operators includes operators like Addition, Subtraction, Multiplication, Division and Modulus. All these operators are binary operators which means they operate on two operands. Below table shows the Arithmetic Operators in JavaScript with examples.

JavaScript Arithmetic Operators |
Operation |
Example |
---|---|---|

+ |
Addition | 10 + 2 = 12 |

– |
Subtraction | 10 – 2 = 8 |

* |
Multiplication | 10 * 2 = 20 |

/ |
Division | 10 / 2 = 5 |

% |
Modulus – It returns the remainder after the division | 10 % 2 = 0 (Here remainder is zero). If it is 10 % 3 then it will be 1. |

**JavaScript Arithmetic Operators Example**

For this example, We are using two variables a and b and their values are 12 and 3. We are going to use these two variables to perform various arithmetic operations present in JavaScript Programming Language

**JAVASCRIPTÂ CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!DOCTYPE html> <html> <head> <title>Javascript Arithmetic Operators</title> </head> <body> <h1>Performing Arithmetic Operations </h1> <script> var a = 12, b = 3; var addition, subtraction, multiplication, division, modulus; addition = a + b; //addition of 3 and 12 subtraction = a - b; //subtract 3 from 12 multiplication = a * b; //Multiplying both division = a / b; //dividing 12 by 3 (number of times) modulus = a % b; //calculation the remainder document.write("Addition of " + a +' and ' + b +" is = " + addition + "<br />"); document.write("Subtraction of " + a +' and ' + b +" is = " + subtraction + "<br />"); document.write("Multiplication of " + a +' and ' + b +" is = " + multiplication + "<br />"); document.write("Division of " + a +' and ' + b +" is = " + division + "<br />"); document.write("Modulus of " + a +' and ' + b +" is = " + modulus + "<br />"); </script> </body> </html> |

**OUTPUT**

**JavaScriptÂ ****Arithmetic Operators Example 2**

For this example also, We are using two variables a and b and their values are 12 and 3. We are going to use these variables to show you, How to display the JavaScript output in Paragraphs.

**JAVASCRIPT CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<!DOCTYPE html> <html> <head> <title>Javascript Arithmetic Operators 2</title> </head> <body> <h1>Performing Arithmetic Operations </h1> <p id = 'add'> Addition </p> <p id = 'sub'> Subtraction </p> <p id = 'mul'> Multiplication </p> <p id = 'div'> Division </p> <p id = 'mod'> Modulus </p> <script> var a = 12, b = 3; var add, sub, mul, div, mod; add = a + b; //addition of 3 and 12 sub = a - b; //subtract 3 from 12 mul = a * b; //Multiplying both div = a / b; //dividing 12 by 3 (number of times) mod = a % b; //calculation the remainder document.getElementById("add").innerHTML = "Addition of " + a +' and ' + b +" is = " + add; document.getElementById("sub").innerHTML = "Subtraction of " + a +' and ' + b +" is = " + sub; document.getElementById("mul").innerHTML = "Multiplication of " + a +' and ' + b +" is = "+ mul; document.getElementById("div").innerHTML = "Division of " + a +' and ' + b +" is = " + div; document.getElementById("mod").innerHTML = "Modulus of " + a +' and ' + b +" is = " + mod; </script> </body> </html> |

**OUTPUT**

Thank you for Visiting our Blog.

## Leave a Reply