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

CodePudding user response:

The
reference 1/f, bubble fish _ 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)

Thank you for your understand

CodePudding user response:

refer to the second floor FnaticE 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

Thank you for your understand

CodePudding user response:

+ + a variable since the first add, it is involved in computing, variable + +, the variables involved in calculation first, since the add again
  • Related