+ 1

++x and x++ in js

Without a var to point to x++ and ++x, what is the difference between them?

12th Jan 2017, 1:47 PM
Efry Eltahan
Efry Eltahan - avatar
2 Answers
+ 1
++x; // prefix x++; //postfix Prefix increments the value, and then proceeds wirh the expression. Postfix evaluates the expression and then performs the incrementing. Prefix example : int x = 3; int y = ++x; // x=4, y=4 Postfix example : int x = 3; int y = x++; // x=4, y=3
12th Jan 2017, 2:08 PM
Guillaume BONHOMMEAU
Guillaume BONHOMMEAU - avatar
+ 1
Thank you for your explanation. This issue is rather confusing. Now at least i understand better
12th Jan 2017, 2:12 PM
Efry Eltahan
Efry Eltahan - avatar