Explain about add and assignment(+=) operator in detail in javascript?


add and assignment(+=) operator

The add and assignment(+=) operator reduces the code little bit.It may not much influential  in small codes whereas coming to long codes it's use can't be ignored.

 Live Demo

Example

<html>
<body>
<script>
   var tot = 0;
   var a = [1,45,78,9,78,40];
   for(var i = 0; i<a.length;i++){
      tot += a[i]
   }
   document.write(tot);
</script>
</body>
</html>

Output

251

Updated on: 30-Jul-2019

116 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements