++someVariable vs. someVariable++ in JavaScript

后端 未结 6 2003
长发绾君心
长发绾君心 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:53

    var a = 1;
    var b = ++a;
    alert('a:' + a + ';b:' + b); //a:2;b:2
    
    var c = 1;
    var d = c++;
    alert('c:' + c + ';d:' + d); //c:2;d:1
    

    jsfiddle

提交回复
热议问题