1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <Scripttype= "Text/javascript">7 8 //The original video explanation is not good, refer to advanced programming9 Ten //forward Increment One var Age= in; A ++Age ; - Console.log (age);// - - //equivalent to the var Age= in; - Age= Age+ 1; - Console.log (age);// - - + //the preceding decrement and this similar - var Age= in; + --Age ; A Console.log (age);// - at - //When you perform a pre-decrement and increment operation, the value of the variable is changed before the statement is evaluated - var Age= in; - varAnotherage= -- Age+ 2; - Console.log (age);// - - Console.log (anotherage); - in - //because the pre-decrement and increment operations are equal to the precedence of the execution statement, the entire statement is evaluated from left to right to varNUM1= 2; + varnum2= -; - varnum3= --NUM1+num2; the varnum4=NUM1+num2; * Console.log (num3);// + $ Console.log (NUM4);// +Panax Notoginseng - //Zhou: In layman's words, the front is the first to add or subtract from yourself, to do well again to do other the + //---------------------------------------------------------------------------------------------------- A the //There is a very important difference between post increment and decrement and pre-increment and decrement, that is, increment and decrement operations are performed after the statement that contains them is evaluated . + //This difference is not a problem in some cases, for example: - var Age= in; $ Age++; $ Console.log (age);// - - - //placing the increment operator behind a variable does not change the result of the statement, because incrementing is the only action for this statement. the //However, when there are other actions in the statement, the differences are obvious, such as: - varNUM1= 2;Wuyi varnum2= -; the varnum3=NUM1-- +num2; - varnum4=NUM1+num2; Wu Console.log (num3);// A - Console.log (NUM1);//1 About Console.log (NUM4);// + $ - //Zhou: In layman's words, the post is the first to do the other, and so on the other, and then add or subtract - - varNUM1= 2; A varnum2= -; + varnum3=NUM1++ +num2; the varnum4=NUM1+num2; - Console.log (num3);// A $ Console.log (NUM1);//3 the Console.log (NUM4);// at the the the - </Script> in the </Head> the <Body> About </Body> the </HTML>
JS Basics _ self-increment and self-subtraction