Arithmetic Operators in Javascript

Arithmetic Operators in Javascript. In the time of web development, javascript is one of the current popular and commonly used programming languages used for front-end developers. It is a client-side language and has a really large library with many inbuilt functions organized for the ease of programming. Like other programming languages, Javascript also provides programmers to perform multiple operations on numbers. There are many types of Operators used in Javascript like Arithmetic Operators, Comparison Operators, Bitwise operators, Assignment Operators, etc. Arithmetic Operators take numerical states both variables or literals and perform the operation on its operands to produce the final result. Generally, arithmetic operators work in the same direction in Javascript like other programming languages except for the division operation.

Types of Arithmetic Operators:)

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Modulus

1. Addition (+)

An addition operator provides the sum of two numbers or the variables containing those numbers. In the position of strings, the addition operator does the String connection.

<p id="addition"></p>
<script>
var a = 120;
var b = 540;
var c = a + b;
document.getElementById("addition").innerHTML = "Sum Of Two Numbers Are... " + c;
</script>

2. Subtraction (-)

As it is genuine that the subtraction operator is used for the subtraction of 2 numbers or the variables holding those numbers.

<p id="Subtraction"></p>
<script>
var a = 620;
var b = 540;
var c = a - b;
document.getElementById("Subtraction").innerHTML = "Subtraction Of Two Numbers Are... " + c;
</script>

3. Multiplication (*)

Multiplication operator is used for the multiplication of two or more numbers or the variables holding those numbers.

<p id="Multiplication"></p>
<script>
var a = 60;
var b = 2;
var c = a * b;
document.getElementById("Multiplication").innerHTML = "Multiplication  Of Two Numbers Are... " + c;
</script>

4. Division(/)

Division operator is used for the division of the 2 numbers where the left operand is dividends and the right operand is the divisor.

<p id="Division"></p>
<script>
var a = 60;
var b = 2;
var c = a / b;
document.getElementById("Division").innerHTML = "Division  Of Two Numbers Are... " + c;
</script>

5. Modulus(%)

The modulus operator returns the remainder passed on by dividing the 2 numbers.

<p id="Modulus"></p>
<script>
var a = 25;
var b = 2;
var c = a % b;
document.getElementById("Modulus").innerHTML = "Modulus  Of Two Numbers Are... " + c;
</script>

Conclusion.

The above statement sharply defines the arithmetic operators used on javascript. There are different types of operators and each type of operator has its own goal. These operators are very basic concepts in any programming language and are trained in the starting only to the newbies before drilling into the deep concepts. So it is very important to learn their use and purpose completely as they form the basis of understanding for a programmer.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top