Theoretical question, if for e.g. I have a big object called Order
and it has a tons on props: strings, numbers, arrays, nested objects.
I have a function:
function removeShipment(order) {
order.shipment.forEach(
// remove shipment action
);
}
Which mean I access only one prop (shipment
), but send a big object.
From perspective of garbage collection and performance is there a difference, between pass Order
and pass Order.shipment
?
Because object passed by reference, and don't actually copy Order
into variable.
Created a simple test here https://jsperf.com/passing-object-vs-passing-raw-value
Test results:
This is syntetic test for passing only one variable, so in other cases results may differ