Creates a new variable of type date D1.
<span style= "Font-family:microsoft yahei;font-size:14px;" >var D1 = new Date (); alert (D1);</span>
The post-run page will pop up:
Fri Sep 16:40:50 gmt+0800
Create a new variable d2, assign the value of D1 to D2, set the D2 year to 2013,
<span style= "Font-family:microsoft yahei;font-size:14px;" >var D2 = D1;d2.setfullyear ("n"); alert (D1 + "/" + D2);</span>
The post-run page will pop up:
Thu Sep 16:40:50 gmt+0800
Thu Sep 16:40:50 gmt+0800
Even if the D2 is declared as a date type, the result is still the same.
<span style= "Font-family:microsoft yahei;font-size:14px;" >var D1 = new Date (), alert (D1), <span style= "color: #FF0000;" >var D2 = new Date (), </span>d2 = D1;d2.setfullyear ("n"), alert (D1 + "/" + D2);</span>
indicates that this direct assignment of the date type becomes a reference value, D1, D2 two variables to the same date object.
It is important to use the "=" symbol to assign values directly to an object in such a way that the result is inconsistent with what you expected, resulting in an incorrect operation.
Value passing and reference passing problems for Javascript Date types