What Is The Arithmetic Operator In JavaScript

admin_img Posted By Bajarangi soft , Posted On 06-10-2020

Arithmetic operators perform arithmetic on numbers (literals or variables),A typical arithmetic operation operates on two numbers,The two numbers can be literals,The numbers (in an arithmetic operation) are called operands,The operation (to be performed between the two operands) is defined by an operator,Operator precedence describes the order in which operations are performed in an arithmetic expression.

JavaScript Arithmetic Operator

1.Arithmetic Operators Example-1(Addition,substraction,multiplication,division):
The two numbers can be literals Example-(1)

<script>
    var x = 100 + 50;
    document.getElementById("demo").innerHTML = x;
</script>
A typical arithmetic operation takes two numbers (or variables) and produces a new number.Example-(2)
<script>
    var a = 100;
    var b = 50;
    var x = a + b;
    document.getElementById("demo").innerHTML = x;
</script>
Takes two numbers (or expressions) and produces a new number Example-(3)
<script>
    var a = 3;
    var x = (100 + 50) * a;
    document.getElementById("demo").innerHTML = x;
</script>
Add Two Numnbers Example-(4)
<script>
    var x = 5;
    var y = 2;
    var z = x + y;
    document.getElementById("demo").innerHTML = z;
</script>
Substracting Example-(4)
<script>
    var x = 5;
    var y = 2;
    var z = x - y;
    document.getElementById("demo").innerHTML = z;
</script>
// multiplication 
<script>
var x=5;
var y=2;
var z=x*y;// we can do division here
document.getElementById("demo").innerHTML=z;
</script>
Increment And Decrement Example-(5)
<script>
    var x = 5;
    x++;
    var z = x;
    document.getElementById("demo").innerHTML = z;
</script>

//decrement 
<script>
    var x = 5;
    x--;
    var z = x;
    document.getElementById("demo").innerHTML = z;
</script>


//Multiplication has precedence over addition
<script>
    document.getElementById("demo").innerHTML = 100 + 50 * 3;
</script>

Related Post