preposed :++a
Add after :a++
contact : When added separately, the result is the same .
difference :a++ Return the original value first Add one more |||||| ++a Add one first Then return to the original value
But the probability of using post addition is a little higher
The results of pre addition and post addition are the same when used alone ! var num = 1; // preposed num++; console.log(num); // Add after ++num;
console.log(num);
Not when used alone :
I'm used to it a++ If : Write first a++ Value of , Is the original value , Rewrite a Value of ( Return the original value first , stay ++)
++a If : Write first a Let him grow by himself 1, Return again ++a Value of ( before ++ Then return to the original value )
Be sure to pay attention to the order I write !!!!
Let's look at the example directly :
var e = 10; e++; // 11 var d = e++ + 2; // e++ 11 e 12 console.log(d); // 13
var a = 10; var f = a++ + ++a; // a++ 10 a 11 ++a 12 a 12 // a key : a++ + ++a in
a++ Return to original value 10 however a++ After execution a become 11 // next ++a Medium a Has become 11 bring a++ become 12 console.log(f); // a++
10 ++a 12 = 22
var a = 10;
var f = a++ + ++a; // a++ 10 a 11 ++a 12 a 12
// a key : a++ + ++a in a++ Return to original value 10 however a++ After execution a become 11
// next ++a Medium a Has become 11 bring a++ become 12
console.log(f); // a++ 10 ++a 12 = 22
Technology