2

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?

1
  • 3
    Passing the whole object would actually be faster / better on memory,.. As your just passing a reference. Commented Mar 28, 2018 at 15:41

1 Answer 1

3

Objects are passed by reference in JavaScript, so passing an object as an argument is basically just passing a memory pointer, which is negligible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.