You got that a bit wrong :). The second
date = new Date();
does not change the first instance created by
var date = new Date();
, but rather replaces it completely. Thus date is now pointing at (referencing) a new instance of the
Date
object while tyt is still pointing (referencing) the original instance.
What you are after is an example like this:
var date = new Date();
var tyt = date;
date.setFullYear(2020);
alert(date);
alert(tyt);
Regards,
Manfred