i++ vs. ++i in a JavaScript for loop

前端 未结 4 870
情书的邮戳
情书的邮戳 2021-02-14 21:23

Because of JSLint, I almost always use i += 1 to increment a JavaScript for loop, but for quick and dirty scripts, I use i++ instead.
However, I se

4条回答
  •  梦毁少年i
    2021-02-14 21:51

    In JS and PHP it does not make any difference, I think even in Java it does not make any difference but in pure c when compiler is not optimizing code it does, and that is why a lot of people use ++i because they are used to it from c.

    EDIT: This is an answer for JS if you want history of pre and post increment searc C/C++ pre/post increment. Or see comments on @Orvev's answer.

提交回复
热议问题