+ 2
Difference between ++x and x++
what is the difference between ++x and x++ I'm JavaScript. give examples pls.
1 ответ
+ 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)