JavaScript Arithmetic Operators: JavaScript Arithmetic Operators includes Addition, Subtraction, Multiplication, Division & Modulus & they are binary operators so they operate on 2 operands.
Read more about JavaScript Tutorial.
The below table shows the Arithmetic Operators in JavaScript with examples:
Operator | Description | Example | Results |
---|---|---|---|
+ | Addition | result = x + y | result = 15 |
– | Subtraction | result = x – y | result = 5 |
* | Multiplication | result = x * y | result = 50 |
/ | Division | result = x / y | result = 2 |
% | Modulus | result = x % y | result = 0 |
++ | Increment | result = x++ result = x result = ++x | result = 10 result = 11 result = 12 |
— | Decrement | result = x– result = x result = –x | result = 12 result = 11 result = 10 |
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> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.