+ 2

Difference between ++x and x++

what is the difference between ++x and x++ I'm JavaScript. give examples pls.

19th Jan 2017, 9:27 AM
freakshow
freakshow - avatar
1 Antwort
+ 20
In prefix case the value of x is calculated first and only then the statement is calculated. Example: var x = 0; var i = ++x; // i == 1, x ==1 In postfix case the statement is calculated first and only then the value of x is calculated. Example: var x = 0; var i = x++; // i == 0, x ==1 Good luck! P.S. In for loop it doesn't matter what type of incrementation/decrementation you use, the result will be the same. Example: for(int i = 0; i < 10; i++) for(int i = 0; i < 10; ++i)
19th Jan 2017, 9:58 AM
Igor Makarsky
Igor Makarsky - avatar