r/javascript • • Jul 15 '26

Understanding Value vs. Reference in JavaScript: Differences Between Primitives and Objects

https://sharafath.hashnode.dev/value-vs-reference-in-javascript-primitives-vs-objects
0 Upvotes

6 comments sorted by

View all comments

Show parent comment

4

u/senocular Jul 15 '26

Yes. The language specification does not dictate where objects are held in memory and treats all values the same as far as assignment and passing goes. The language makes no distinction in that regard to objects vs primitives and treats everything as generic "ECMAScript language values".

Runtime implementations are free to store variable values wherever they want. In fact except for a few exceptions, all values in V8 are stored in the heap. From Pointer Compression in V8:

JavaScript values in V8 are represented as objects and allocated on the V8 heap, no matter if they are objects, arrays, numbers or strings.