+ 1

Increment operator (++) & decrement operator (--).

Please help me friends to understand the basics of increment operator (++) & decrement operator (--). Any reply is appreciated .

6th Mar 2017, 1:39 PM
Abdel
Abdel - avatar
5 Réponses
+ 4
@Alejandro gave a proper explanation. let me give you an example which will clear it out: var x = 0; var y; y = x++; //here y is 0 and x is 1 //first assign then increment var x = 0; var y; y = ++x; //here y is 1 and x is 1 //first increment then assign Same is the case with --x and x--
6th Mar 2017, 2:23 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 4
Because I guess statement y = x++ will be interpreted as y = x; x = x+1; & y = ++x as x = x+1; y=x; By Javascript interpretor.
6th Mar 2017, 2:36 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 3
var++ is equal to var=var+1; You could have pre increment, ++var this increments the variable first, before the line executes... And post increment, that increments the variable after the line execution. Same happens with -- just with the difference that you are substracting
6th Mar 2017, 1:50 PM
Alejandro Serrato
Alejandro Serrato - avatar
+ 1
but y = x++ shouldn't be y = x + 1 first which will be 1 ???? because if i do understand x++ means x = x + 1 ??? Thanks for replying
6th Mar 2017, 2:32 PM
Abdel
Abdel - avatar
+ 1
that was awesome and clear enough please let's turn ti (--) thanks for helping
6th Mar 2017, 2:49 PM
Abdel
Abdel - avatar