In JavaScript, incrementing decrements belong to the unary operator, the so-called unary operator, which is an operator that can manipulate only one value.
Increment and decrement operators are available in two versions: pre-and post-built. As the name implies, the predecessor should precede the variable to be manipulated, and the latter should precede the variable to be manipulated.
01, pre-type operator use:
var age=29; //Equals - equivalent to var age=29;age//equals
When you perform a pre-increment and decrement operation, the value of the variable is changed before the statement is evaluated.
var num1=2; var num2=20; var num3=--num1+num2; // equal to var // equal to
02, post-type operator use:
var age=29;age//equals
There is a very important difference between post increment, decrement and forward increment and decrement, that is, increment and decrement operations are performed after the statement that contains them is evaluated.
var num1=2; var num2=20; var num3=num1--+num2; // equals var // equal to
All of these four operators apply to any value, that is, they apply not only to integers, but also to strings, Boolean values, floating-point values, and objects.
varS1= "2";varS2= "Z";varb=false;varf=1.1;varo={valueOf:function(){ return-1; }};S1++;//The value becomes the number 3s2++;//value becomes Nanb++;//The value becomes the number 1f--;//value becomes 0.10000000000000009 (due to floating-point rounding errors)o--;//value becomes numeric-2
Increment decrement operator in JavaScript