How to Use of Arithmetic Operator in JavaScript

In this article I have described about the Arithmetic operator used in JavaScript
  • 2481

JavaScript Operator - Arithmetic Operator

  • An operator is used to transform one or more value into a single resultant variable.
  • The value to which the operator is applied is referred as operands.
  • A combination of an operator and its operand referred as an Expression.

NOTE

  • for some operator such as multiplication (*) the order of the operand do not matter. for example A*Y=Y*A true for all integer and floating point number.
  • Other operator like String concatenation (+), the order of operand matter. for example- "ab" +"cd" not same as  "cd" +"ab".

lets take an example

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript Oerator</title>
<body>

<p>JavaSript + operator example with variable</p>
<button onclick="myFunction()">CLICK</button>
<p id="demo"></p>
<script type="text/javascript">
function myFunction() 
{
txt1 = "welcome to";
txt2 = " MCN IT SOLUTION ";
txt3 = txt1 + txt2;
document.getElementById("demo").innerHTML = txt3;
}
</script>
</body>
</head>
</html>

 

when we run above program


op.jpg

 

Arithmetic Operator


The table having some Arithmetic operator

 

    Operator          Description                       Example
+ add two operand x=y+2
- subtract second operand from first one x=y-2
* multiply both operand x=y*2
/ divide numerator by denumerator x=y/2
% modulus operator x=y%2
++ Increment Operator x=++y  x=y++
-- Decrement Operator x=--y  x=y--

Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.