JavaScript Arithmetic

JavaScript Arithmetic Operators

Arithmetic operators perform arithmetic on numbers

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement

Arithmetic Operations


A typical arithmetic operation operates on two numbers.

The two numbers can be literals or Variables

The addition operator (+) adds numbers:

Example

<script>
var x,y,z; ⁄ ⁄declare vaariables
x=5;
y=10;
z=x+y;
document·write("Addition of "+ x +"+"+ y+"="+z+"<br/>");
</script>

Run Example>>




Note:
  • Using "+" we can concate string in Javascript;
  • The subtraction operator (-) subtracts numbers.

    Example

    <script>
    var x,y,z; ⁄ ⁄declare vaariables
    x=10;
    y=5;
    z=x-sy;
    document·write("Addition of "+ x +"-"+ y+"="+z+"<br/>");
    </script>

    Run Example>>




    Note:
  • Like above example we can perform all Arithmetic Operations