Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?

前端 未结 16 1350
庸人自扰
庸人自扰 2020-11-22 06:23

One of the tips for jslint tool is:

++ and --
The ++ (increment) and -- (decrement) operators have been known to contribute

16条回答
  •  清歌不尽
    2020-11-22 06:42

    My view is to always use ++ and -- by themselves on a single line, as in:

    i++;
    array[i] = foo;
    

    instead of

    array[++i] = foo;
    

    Anything beyond that can be confusing to some programmers and is just not worth it in my view. For loops are an exception, as the use of the increment operator is idiomatic and thus always clear.

提交回复
热议问题