javascript - Why my variable "c" has changed? -
var c = new date(2015, 11, 25); var d = c; d.setfullyear(2000); console.log(c); console.log(d);
//why variable "c" has changed in code?
line 1: create date object , assign reference c
.
line 2: copy value of c
(a reference date object) d
line 3: modify date object. still referenced 2 variables.
if want create new date object , assign d
need explicitly.
var c = new date(2015, 11, 25); var d = new date(c); d.setfullyear(2000); console.log(c); console.log(d);
Comments
Post a Comment