This warning has existed in two forms in JSLint and ESLint. It was introduced in the original version of JSLint and has remained in both tools since. It is not present in JSHint.
In JSLint the warning given is "Unexpected '++'" (or "Unexpected '--'")
In ESLint the message has always been "Unary operator '++' used" (or "Unary operator '--' used")
The situations that produce the warning have not changed despite changes to the text of the warning itself.
The "Unexpected '++'" error, and the alternative "Unary operator '++' used", is
thrown when JSLint or ESLint encounters a use of the increment or decrement
operators. In ESLint the warning is only raised if the
no-plusplus option is
1. Here's an example:
var x = 1, y = 10; x++; y--;
This error message is perhaps the most debated of all JSLint error messages. It exists solely to warn you that JSLint has encountered a violation of a specific coding style. The style in question is the style of the author of JSLint, Douglas Crockford. For his reasoning, you can read the JSLint documentation:
The ++ (increment) and -- (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces. Also, preincrement/postincrement confusion can produce off-by-one errors that are extremely difficult to diagnose.
var x = 1, y = 10; x = x + 1; // or x += 1; y = y - 1; // or y -= 1;
If you would prefer not to do that, and would rather stick with the normal
increment and decrement operators, you can set the
plusplus option to
to tell JSLint to allow them:
/*jslint plusplus: true */ var x = 1, y = 10; x++; y--;
In ESLint the rule that generates this warning is named
can disable it by setting it to
0, or enable it by setting it to