When i'm trying to know functionality of setDate() ,setTime() of javscript date i came across this problem.
<script>
var date1 = new Date();
var date2 = new Date(1991,4,11);
var date3 = new Date(1992,4,11);
date3 = date1;
date2 = date1;
date2.setDate(date2 .getDate() + 40);//im changing only date2 value using setDate()
//print values
</script>
I think the result will be like:
Fri Jul 04 2014
Wed Aug 13 2014
Fri Jul 04 2014
But in output all date variables have same value:
Wed Aug 13 2014
Wed Aug 13 2014
Wed Aug 13 2014
If i do similar kind of code with integer variables they work like as i think(all int variables have different values).
Summary of Questions
- How date assignment and number assignment differs?
- Why and how javascript setDate() tracking other date variables?
- Last but not least What i have to do if i want to change only date2 value with these assignments?
Thanks in Advance.