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

JavascriptObject Oriented ProgrammingProgramming

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
raja
Published on 21-May-2019 16:37:43
Advertisements