Arithmetic operators are used to perform arithmetic operations.
JavaScript Arithmetic Operators List:
Operator | Description | Example |
+ | Addition | 30+20 = 50 |
– | Subtraction | 30-10 = 20 |
* | Multiplication | 10*10 = 100 |
/ | Division | 50/10 = 5 |
Modulus (Remainder) | 50%7 = 1 | |
++ | Increment | var a=10; a++; Result into a = 11 |
— | Decrement | var a=10; a–; Result into a = 9 |
JavaScript Arithmetic Operators Example:
<html> <head> <script type="text/javascript"> var a = 33; var b = 10; var c = "Test"; var linebreak = "<br />"; document.write("a + b = "); result = a + b; document.write(result); document.write(linebreak); document.write("a - b = "); result = a - b; document.write(result); document.write(linebreak); document.write("a / b = "); result = a / b; document.write(result); document.write(linebreak); document.write("a result = a document.write(result); document.write(linebreak); document.write("a + b + c = "); result = a + b + c; document.write(result); document.write(linebreak); a = ++a; document.write("++a = "); result = ++a; document.write(result); document.write(linebreak); b = --b; document.write("--b = "); result = --b; document.write(result); document.write(linebreak); </script> </head> <body> </body> </html>