1

I'm working with dates and my code is like the following:

(currentDate is just the actual date to remember and shownDate is a variable that is changed in a function to get date specific data from my database

var currentDate = new Date();
var shownDate = currentDate;

Now if I change shownDate (like add 7 days) currentDate is changed as well. I know that assigning variables like that makes shownDate something like pointing at currentDate thus changing it as well.

Let me know if you need some more code or anything else.

Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
tiko_2302
  • 101
  • 8

1 Answers1

3

You can clone with new Date:

var currentDate = new Date();
var shownDate = new Date(currentDate);
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151