JS Basics _ self-increment and self-subtraction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.