JavaScript warning Lint inc_dec_within_stmt

Can someone explain the reason / importance of why javascriptlint (not jslint) gives a warning

inc_dec_within_stmt - increment (++) and decrement (--) operators used as part of greater statement 

when it gets into a line of code for example

 someValue = count++; 

Why should I keep this check enabled?

+3
source share
1 answer

This is a warning, because such a statement may be ambiguous for readers.

While you and I can look at it and understand that it is equivalent

 someValue = count; count = count + 1; 

a less experienced programmer may misinterpret this as

 someValue = count + 1; 

Of course, this is the simplest example. A warning is much more deserved in a string like

 someValue = (count++) * (--index) / (3 * ++j); 

although I cannot say that I have ever seen such a line in production code :)

+5
source

Source: https://habr.com/ru/post/1395305/


All Articles