Suppose we have the following js function that processes Date objects:
targetDate and referenceDate are for Date objects.
function validateDate(targetDate, referenceDate) { if (targetDate < referenceDate) return referenceDate; else return targetDate; }
Now suppose we want the returned object to be a new instance, and not a pointer to the same memory address as the input parameters.
To do this, is it necessary to replace return dateObjectInstance with return new Date(dateObjectInstance) , or does return already instantiate a new object?
In other words: Objects returned by reference or instantiated by a new instance?
source share