Home >Common Problem >What is the difference between x-- and --x
The difference between x-- and --x: 1. [--x] decrements the value of x by 1 first, and then calculates the value of x; 2. [x--] calculates x first value, and then decrement the value of x by 1.
##The difference between x-- and --x:
- -x means that the value of x is decremented by 1 first, and then the value of x is calculated.
x-- is to first calculate the value of x, and then decrement the value of x by 1.
var x = 10; console.log(x--); console.log(x);Output:
10 9The first output is 10, x--first use the value of x in the current expression , and then decrement the value of x by 1; the second output is 9, because x has decremented by 1 after the previous instruction. Example 2:
var x = 10; console.log(--x); console.log(x);Output:
9 9The first output is 9, --x first decrements the value of x by 1, and then in the current expression Use the value of x; the second one also outputs 9, and x has been decremented by 1 after the previous instruction.
The above is the detailed content of What is the difference between x-- and --x. For more information, please follow other related articles on the PHP Chinese website!