This article describes the continuous assignment problem in JavaScript. Share it for your reference, as follows:
Continuous assignment in JavaScript:
<script> var a = {n: 1} var b = a; = a = {n: 2} ();//undefined ()//Object {n: 2} </script>
The priority of the assignment operator "=" in Javascript is the lowest except "," and is combined from right to left.
The order of operations in Javascript is from left to right.
= a = {n: 2}
Can be seen as =(a = {n: 2})
, first perform calculation, add x attribute to a, the result isnull, in the calculation expression(a = {n: 2})
, and finally perform the assignment operation.
Modify the program:
<script> var a = {n: 1} var b = a; a = = {n: 2} ();//undefined ()//Object {n: 2} </script>
<script> var a = {x:{xx:1},y:2,z:3}; var b = ; //{xx:1} var c = a; = = = a = {x:10,y:20}; (a); (b); (c); </script>
Running results:
a : {x: 10, y: 20}
b : {xx : {x: 10, y: 20}}
c :?{x:{xx:{x:10,y:20}},y:{x:10,y:20},z:3,w:{x:10,y:20}}
<script> ();//10 ();//10 ();//10 </script>
Friends who are interested in the above code can use itOnline HTML/CSS/JavaScript code running tool:http://tools./code/HtmlJsRunTest run results.
For more information about JavaScript, you can also view the topic of this site: "JavaScript object-oriented tutorial》、《Summary of JavaScript Errors and Debugging Skills》、《Summary of JavaScript data structure and algorithm techniques》、《JavaScript traversal algorithm and skills summary"and"Summary of JavaScript mathematical operations usage》
I hope this article will be helpful to everyone's JavaScript programming.