I want to pass a date to a javascript function for some manipulation. The problem I am facing here is: the function is changing the actual date parameter though it works on a local parameter. Here is an example where I have mentioned my issue
var myDate = new Date();
console.log(myDate);//Result is Mon Oct 22 2018 09:40:01
function manipulate(d){
d.setDate(d.getDate()+1);
console.log(d);//Result is Oct 23 2018 09:40:01
return d;
}
var result = manipulate(myDate);
console.log(result);//Result is Oct 23 2018 09:40:01 as expected.
console.log(myDate);//Result is Oct 23 2018 09:40:01. I want this to be my initial value. That is Mon Oct 22 2018 09:40:01
I guess it JS uses pass by reference if the date is used as a parameter. How can I resolve the above-mentioned issue?
Regards,
SAP Learner