0

assume the following

const a = { name: 'John Doe', age: 20 };
const b = a;

b is only assigned the reference of the object from a. How much memory does this reference value assignment take up?

alaboudi
  • 3,187
  • 4
  • 29
  • 47
  • 1
    Seems like an implementation detail that depends on the engine. Why does the exact amount of memory matter? All that matters is that a new JS object isn't allocated and you can access the same memory location with either `a` or `b`. – ggorlen Nov 02 '20 at 16:54
  • This is just something I'm researching. For most people it may not have practical implications. Seems like a very fundamental concept for it be based on engine implementation. Do you know where I can validate this information? – alaboudi Nov 02 '20 at 16:57
  • You could consult the documentation and source code for whatever engine you're using. I don't think it has practical implications--can you describe your use case where knowing exactly how much memory an alias variable uses matters? It should be virtually nothing on any implementation, I'd imagine. – ggorlen Nov 02 '20 at 17:00
  • 1
    You'll need to read the spec to understand the intent of TC-39, but then you'll need to read the implementation details for each independent browser (you might start with chromium). This question is related: https://stackoverflow.com/questions/2800463/how-variables-are-allocated-memory-in-javascript. -- here is a [Chromium Reference](https://chromium.googlesource.com/chromium/src.git/+/master/docs/memory/key_concepts.md) – Randy Casburn Nov 02 '20 at 17:01

0 Answers0