+ 1
What is the difference between pre and post increment and decrement operators?
Pre and post increment and decrement operators are being a drag for me!
6 odpowiedzi
+ 7
PRE ➡ Happens BEFORE end of statement
POST ➡ Happens AFTER end of statement
These apply for both ➕➕ and ➖➖.
+ 1
++4 = 4
& 4++ =6
+ 1
IN PREFIX ++x FIRST x IS INCREMENTED AND THAN EVALUATION TAKE PLACE.
IN POSTFIX x++ FIRST EVALUATION IS DONE AND THAN ITS VALUE IS INCREMENTED.
Decrement goes same way.
Hope this helps ☺️☺️.
+ 1
Small example
x = x + x++ + ++x + x
=4
+ 4(post increment now x=5)
+ 6(pre increment)
+ 6.
=20
+ 1
postfix: x=5 y=x++ so, x =6 y=5
if you ask why.. assign x value to y first
x=5 y=5
then increment
x=6 y=5
prefix
.. just add both first
+ 1
pre increment increments the value by 1 before returning the value.
pre: a = ++1;
document.write(a); //2
post increment returns the value first then increments it.
post: a = 1++;
document.write(a); //1
Decrement works the same way as increments.