++someVariable vs. someVariable++ in JavaScript

后端 未结 6 1931
长发绾君心
长发绾君心 2020-11-22 02:02

In JavaScript you can use ++ operator before (pre-increment) or after the variable name (post-increment). What, if any, are the differences b

6条回答
  •  既然无缘
    2020-11-22 02:51

    As I understand them if you use them standalone they do the same thing. If you try to output the result of them as an expression then they may differ. Try alert(i++) as compared to alert(++i) to see the difference. i++ evaluates to i before the addition and ++i does the addition before evaluating.

    See http://jsfiddle.net/xaDC4/ for an example.

提交回复
热议问题