
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Why should we not use ++, -- operators in JavaScript?
The increment (++) and decrement (---) operators should be avoided since it can lead to unexpected results. Here are some of the conditions −
Example
In an assignment statement, it can lead to unfavorable results −
<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;
- Related Articles
- Why should we use element in JavaScript?
- Why should we not use an umbrella during lightning?
- Why we should not use tables for HTML Layout?
- Why should we use a semicolon after every function in JavaScript?
- Why we should not waste water?
- Why we should use set.seed in R?
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘
- Why should we use MySQL CASE Statement?
- Why do we use "use strict" in JavaScript?
- Why we should not eat food in lying down position?
- Why we should use whole string in Java regular expression
- What is SciPy and why should we use it?
- Why do we Use JavaScript in HTML?
- When you should not use JavaScript Arrow Functions?
- Why we should not pick up caterpillars with bare hands ??

Advertisements