When would you use postfix vs the prefix ? Please show an example? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

When would you use postfix vs the prefix ? Please show an example?

26th Sep 2016, 2:42 AM
Muby
2 Answers
+ 5
When you want something incremented/decremented before you use the variable, you must use prefixed operator, otherwise the variable will be used first and icremented after: e.g. var i = 0; var j = 0; document.write(++i); document.write(j++); The values printed will be respectively 1 and 0. The use of each other will vary accordingly with your necessity.
27th Sep 2016, 11:51 PM
Rodrigo Estevao
Rodrigo Estevao - avatar
0
in simple way Suppose u have any variable like Int a=10; and u want to use it start with 11 then u need preIncrement... it increments the value first then exicute.. int a =10; system.out.println(++a); output = 11
6th Nov 2016, 6:16 PM
Mukesh Kumaar
Mukesh Kumaar - avatar