JavaScript Lint inc_dec_within_stmt warning
-
16-09-2019 - |
Question
Can someone explain the reason/importance of why javascriptlint (not jslint) gives the warning
inc_dec_within_stmt - increment (++) and decrement (--) operators used as part of greater statement
when it comes across a line of code like
someValue = count++;
Why should I keep this check turned on?
Solution
It's a warning because a statement like that can be ambiguous to human readers.
While you and I can look at that and understand that it is equivalent to
someValue = count;
count = count + 1;
a less experienced programmer might incorrectly interpret that as
someValue = count + 1;
Of course, this is the simplest example. The warning is much more deserved in a line like
someValue = (count++) * (--index) / (3 * ++j);
although I can't say I've ever seen a line like that in production code :)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow