+ 4

Increment & Decrement

I can't understand this topic.... Can anybody explain plz... https://www.sololearn.com/learn/JavaScript/1130/?ref=app

4th Oct 2020, 2:46 PM
Superone_S - avatar
4 Answers
+ 8
Example Increment x=6 ,y= 7 x++ means the value of x will increase by one and when u use the value of x u will find it's value = 7 but if u only write x++ and print x u will find the value is 6 ex: ++x + y++ = 7 + 7 = 14 #but if u wanna use the variable y in any operation u will find the value = 8 and x = 7 Decrement x= 6 ,y= 7 x-- + --y = 6 + 6 = 12 #and if u wanna use the value of x in othet operation u will find the value of x = 5 and the value of y = 6
4th Oct 2020, 3:05 PM
Muhammad - avatar
+ 5
Increment ++ and decrement -- are operators which increase or decrease a variable value by 1. Often i++ and ++i equal i+=1, similarly i-- and --i equal i-=1, but with increment and decrement operators you are also allowed to use the variable for other purposes, in 1 statement. For example you can use variable value for addition while incrementing the variable: int i = 0; int j = 5 + ++i; //i = 1, j = 6. Above we incremented variable i by 1 and used its new value 1 to the addition. It matters, whether ++ is on the left or right side of the variable, but it only matters, when the variable is being used for the (previously mentioned) other purposes. When it's on left (prefix): ++i You would use the new, the incremented value for the other purposes, and when it's on right (postfix): i++ You would use the original, the unincremented value for the other purposes. This would for affect the result of the previous example, where we used prefix, if we set it to postfix: int i = 0; int j = 5 + i++; //i = 1, j = 5.
4th Oct 2020, 3:37 PM
Seb TheS
Seb TheS - avatar
+ 4
You need to print the actual increment to see what's happening a=1; Document.write(a++); a = 1; document.write(++a);
4th Oct 2020, 5:37 PM
D_Stark - avatar
+ 3
Those simples js addition operation just get the sum of all numbers and document.write will display the result.But eval function will convert the operation included into a string format to integer result .
4th Oct 2020, 3:00 PM
HBhZ_C - avatar