Computer Science, asked by parthprajapati8354, 1 year ago

Why should we not use ++, -- operators in JavaScript?

Answers

Answered by saranyaammu3
0

Answer:

The increment (++) and decrement (---) operators should be avoided since it can lead to unexpected results. Here are some of the conditions:

In an assignment statement, it can lead to unfavorable results:

Live Demo

<html>    

  <body>      

     <script>          

        var a = 5;          

        var b = ++a;          

        var c = a++;          

        var d = ++c;              

        document.write(a);          

        document.write("\r"+b);          

        document.write("\r"+c);          

        document.write("\r"+d);            

     </script>    

  </body>

</html>

Whitespace between the operator and variable can also lead to unexpected results:

a = b = c = 1; ++a ; b -- ; c;

Explanation:

Similar questions