+ 1
Increment operator (++) & decrement operator (--).
Please help me friends to understand the basics of increment operator (++) & decrement operator (--). Any reply is appreciated .
5 Respuestas
+ 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--
+ 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.
+ 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
+ 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
+ 1
that was awesome and clear enough please let's turn ti (--)
thanks for helping