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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -