 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
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:
Example
<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>  Output
Whitespace between the operator and variable can also lead to unexpected results:
a = b = c = 1; ++a ; b -- ; c;
Advertisements
 