Computer >> Computer tutorials >  >> Programming >> Javascript

write about the arithmetic operator in javascript?


JavaScript arithmetic operators include Addition, subtraction, Division, Multiplication. let's see some of them

1) Addition and modulus operators

Example

<html>
<body>
<p id="add"></p>
<script>
   var tot = 0;
   var a = [1,2,3,4,5,6,7,8,9]
   for (var i = 0; i < a.length; i++) {
      if(a[i]%2 == 0) {
      tot += a[i]
      }
   }
   document.getElementById("add").innerHTML = tot;
</script>
</body>
</html>

Output

20


2) Multiplication operator

Example

<html>
<body>
<p id="mul"></p>
<script>
   var pro = 1;
   var a = [1,2,3,4,5,6,7,8,9]
   for (var i = 0;i<a.length;i++) {
      pro *= a[i]
   }
   document.getElementById("mul").innerHTML = pro;
</script>
</body>
</html>

Output

362880