Why is JavaScript's post-increment operator different from C and Perl?

后端 未结 4 606
盖世英雄少女心
盖世英雄少女心 2021-01-05 17:39

I\'m studying for an exam on JavaScript at the moment. I\'ve also got a little knowledge of C and Perl so I\'m familiar with prefix and postfix operators in all three langua

4条回答
  •  一生所求
    2021-01-05 18:17

    Basically, the value of x is decemented after assignment. This example might make it clearer (run in Firebug console)

    var x = y =10;    
    x += y--;        
    console.log(x , y); // outputs 20 9
    

提交回复
热议问题