Reputation: 4112
Whenever I only need one specific object property, I will pass that property to the function, but I've seen my colleagues passing the whole objects only to use 1 value. Intuitively I believe my way is better, but I'd like to really know if it's better purely from the point of memory management.
const largeObj = {...};
dummyFn1(largeObj);
dummyFn2(largeObj.name);
So in essence - is there any difference in memory allocation between these two functions?
Upvotes: 2
Views: 89
Reputation: 4106
Objects are passed by reference in JavaScript, so passing an object as an argument is basically just passing a memory pointer, which is negligible.
Upvotes: 3