Home > front end > JavaScript arithmetic operators in the prefix, suffix and prefix add is to add one after the operati
JavaScript arithmetic operators in the prefix, suffix and prefix add is to add one after the operati
Time:04-26
CodePudding user response:
Let a=120
//a=a + 1=121 + + a
//a=a + 1=122 +
//a=122 The console. The log (a)
//b=a + 1=123; A=a + 1=123 Const=a + b + a
//c=a, a=a + 1=124 Const=c +
//124123123 The console. The log (a, b, c)
CodePudding user response:
First of all, since the increase/decrease since can only be applied to variables, applied to the numerical value (such as 120 + +) may be an error, Secondly, since the operator + +, after before the variable or variables, the meaning is the same,
let counter=120; Counter++; Or + + counter; counter;//121
So is there any difference between them? Yes, but only when we use the + +/- to see when the return value of the difference, in particular, this is the counter back to another variable, this can reflect the difference: + + front form returns a new value, but the rear + + return to the original value:
let counter=120; Let a=+ + counter;//+ + front a;//121
let counter=120; Let a=counter++;//+ + rear a;//120