JavaScript Lint inc_dec_within_stmt warning

别来无恙 提交于 2019-12-10 22:05:55

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/1132001/javascript-lint-inc-dec-within-stmt-warning

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!