+ 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!

18th Jul 2018, 1:20 PM
Shreyal Sharma
Shreyal Sharma - avatar
6 Answers
+ 7
PRE ➡ Happens BEFORE end of statement POST ➡ Happens AFTER end of statement These apply for both ➕➕ and ➖➖.
18th Jul 2018, 1:46 PM
Zephyr Koo
Zephyr Koo - avatar
+ 1
++4 = 4 & 4++ =6
18th Jul 2018, 1:45 PM
Manthan Butani
Manthan Butani - avatar
+ 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 ☺️☺️.
18th Jul 2018, 1:47 PM
Meet Mehta
Meet Mehta - avatar
+ 1
Small example x = x + x++ + ++x + x =4 + 4(post increment now x=5) + 6(pre increment) + 6. =20
18th Jul 2018, 1:51 PM
Meet Mehta
Meet Mehta - avatar
+ 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
18th Jul 2018, 3:23 PM
‎צחק‎اسحاق
‎צחק‎اسحاق - avatar
+ 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.
19th Jul 2018, 2:26 PM
Glow❤✨
Glow❤✨ - avatar