JavaScript Arithmetic Operators

JavaScript Arithmetic Operators are used to compute arithmetic operations on given numeric values.

Arithmetic Operator Symbol Example

JavaScript supports the following arithmetic operators.

Arithmetic Operation Operator Symbol Example
Addition + a + b
Subtraction a - b
Multiplication * a * b
Division / a / b
Modulus % a % b
Increment ++ a++, ++a
Decrement a--, --a

Tutorials

The following JavaScript tutorials cover each of these arithmetic operators in detail.

Example

In the following example, we take two values, and perform different Arithmetic Operations on these values.

index.html

<!DOCTYPE html>
<html lang="en">
<body>
    <pre id="output"></pre>
    <script>
        var a = 7;
        var b = 4;
        var addition = a + b;
        var subtraction = a - b;
        var multiplication = a * b;
        var division = a / b;
        var modulus = a % b;
        var increment = ++a;
        var decrement = --b;

        var displayOutput = '';
        displayOutput += '\n' + 'a + b = ' + addition ;
        displayOutput += '\n' + 'a - b = ' + subtraction ;
        displayOutput += '\n' + 'a * b = ' + multiplication ;
        displayOutput += '\n' + 'a / b = ' + division ;
        displayOutput += '\n' + 'a % b = ' + modulus ;
        displayOutput += '\n' + '++a = ' + increment ;
        displayOutput += '\n' + '--b = ' + decrement ;
        document.getElementById('output').innerHTML = displayOutput;
    </script>
</body>
</html>

Conclusion

In this JavaScript Tutorial, we learned about Arithmetic Operators, their syntax, and usage with examples.