JS even assignment

Source: Internet
Author: User

Reference: http://www.iteye.com/topic/785445

https://segmentfault.com/q/1010000002637728

This is a problem

1  var a = {N:1};//a points to a piece of address {n:1}; 2  var b = A;  Hold A to check back  //b's reference to a, also point to the address {n:1}; 3  a.x = a = {N:24  //5  // --- {N:2} 

JS assignment is right-associative, starting from the right to the left to assign values

1 // equivalent to 3 A1 = (A2 = A3)4// so all are A3 values

The problem above is that:

A.x=a={n:2};

False conjecture: A first assignment {n:2},a.x discovery A is overridden (before a is {a:1}), a.x = {N:2} engine restricts a.x assignment, ignored. (because b.x has output)

Previous status:

After assignment:

That is to say, a.x still points to the previous address, and a point to a new address {N:2}, which no longer points to the previous address. If there is no B, the value of the a.x is not found (but it exists, but there is no pointer pointing to it).

A.x points to the previous address because: . operator precedence over = assignment Operation

1. First declare the x attribute of the A object (A to {n:1})

2. Assign a value to a, point to {N:2}

3, then the a.x assignment (the original A, that is, b)

In addition, a global variable appears with the use of a hyphen symbol.

1 (function() {2var a=b=1; 3 } ())4//1    becomes global variable 5//error, because there is no

JS even assignment

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.