Title: differences between a ++ and

Source: Internet
Author: User

Title: differences between a ++ and

I used to understand the differences between a ++ and ++ a. After reading a lot of information, I finally came up with a rule dedicated to Tom!

After reading this example, I understand: Example 1: $ a = 8. How much does ++ a + a ++--- a + a -- ++ a get? Old value: 8 9 10 9 8 + + a ++--- a + a -- ++ a new value: 9 10 9 8 9 return value: 9 9 9 8 9 results are equal to: 9 + 9 + 9 + 8 + 9 = 26. Explanation: whether a ++ or ++ a, a must implement it by itself, however, if it is a ++, the returned value is the old value. If it is ++ a, the returned value is the new value. therefore, the result from the expression is 26. example 2:

Var a = 3;
Var goos = function (){
Return a ++;
}
Console. log (goos ());

The result must be 3;

 

Example 3:

Var a = 3;
Var goos = function (){
Return ++;
}
Console. log (goos ());

The result must be 4;

Explanation: No matter whether a ++ or ++ a, a must be implemented by itself. However, if it is a ++, the returned value is the old value. If it is ++, the return value is a new value. original articles cannot be reproduced without permission!

Related Article

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.