Regarding the google-datalayer, there is a distinction in Javascript between passing primitives by value and objects by reference. For example:
var price = 3;
var object_with_price = { price: 3 };
var data_with_price = { value: price };
var data_with_object = { value: object_with_price };
If you update price
to 4, data_with_price.price
will still reflect the original value of 3 because it was passed by value.
However, if you change object_with_price.price
to 4, then data_with_object.value.price
will also be updated to 4.
By assigning object_with_price = { price: 5 }
, data_with_object
will remain unaffected.