
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What are Arithmetic Operators in JavaScript?
JavaScript supports the following arithmetic operators. Assume variable A holds 10 and variable B holds 20, then −
Sr.No | Operator and Description |
---|---|
1 | + (Addition) Adds two operands Ex: A + B will give 30 |
2 | - (Subtraction) Subtracts the second operand from the first Ex: A - B will give -10 |
3 | * (Multiplication) Multiply both operands Ex: A * B will give 200 |
4 | / (Division) Divide the numerator by the denominator Ex: B / A will give 2 |
5 | % (Modulus) Outputs the remainder of an integer division Ex: B % A will give 0 |
6 | ++ (Increment) Increases an integer value by one Ex: A++ will give 11 |
7 | -- (Decrement) Decreases an integer value by one Ex: A-- will give 9 |
The following code shows how to use arithmetic operators in JavaScript.
Example
<html> <body> <script> <!-- 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 % b = "); result = a % b; 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> Set the variables to different values and then try... </body> </html>
- Related Articles
- What are arithmetic operators in C#?
- What are the arithmetic operators in Java?
- What are different arithmetic operators in Python?
- What are the arithmetic and character operators in DBMS?
- What are operators in JavaScript?
- Arithmetic Operators in C++
- What are JavaScript Operators
- Java arithmetic operators
- Python Arithmetic Operators
- Perl Arithmetic Operators
- What are Comparison Operators in JavaScript?
- What are Logical Operators in JavaScript?
- What are Assignment Operators in JavaScript?
- What are Conditional Operators in JavaScript?
- What is operand of arithmetic operators in Java

Advertisements