Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Lint inc_dec_within_stmt warning

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?

like image 773
Luke Smith Avatar asked Sep 10 '26 08:09

Luke Smith


1 Answers

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 :)

like image 129
Mark Rushakoff Avatar answered Sep 11 '26 23:09

Mark Rushakoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!