Title: Javascript Object.create: what happens to memory when data is set?
Tags: javascript;javascript-objects
Question: Let's say in Javascript a new Object is being created with a method to set data to the created instance.
I am wondering, when that data has been added, will that data exist twice in memory or do newObj.data and data simply point to the same address in memory?
let data = {text: 'a text'};
let newObj = Object.create({
setData(argData) {
this.data = argData;
// is data and newObj.data twice in memory now?
I apologize in advance if similar questions might have been asked already (that's what the editing hint at the time of writing this indicated). I so, I haven't found them. May be they were formulated differently, but I don't know how to ask this question in any other way.
Comment: if you call function setData both data and this.data will point to the same object, in JS they passed by reference.

Comment: @jcubic - Best to avoid "passed by reference." It's a term of art meaning something else. It's just that the value is a reference, and that value is copied.

Here is the accepted answer: I am wondering, when that data has been added, will that data exist twice in memory or do newObj.data and data simply point to the same address in memory?
The latter. What's held in newObj.data and data is something called an object reference, not the object itself. The object is elsewhere in memory (just once); the reference is a value telling the JavaScript engine where the object is.
That's assuming that you ever actually call newObj.setData(data). Just the Object.create itself doesn't set the data property on the newObj.
Let's throw some inielsen@example.com. After you do this:
let data = {text: 'a text'};
let newObj = Object.create({
setData(argData) {
this.data = argData;
...you have something like this in memory (various details omitted):
+−−−−−−−−−−−−−−−−+
data:[Ref54611]−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−>|   (object)     |
+−−−−−−−−−−−−−−−−+
| [[Prototype]]  |−−+
| text: 'a text' |  |
+−−−−−−−−−−−−−−−−+  |
|
+−−−−−−−−−−−−−−−−+                            +−>(Object.prototype)
newObj:[Ref74135]−−−>|   (object)     |                            |
+−−−−−−−−−−−−−−−−+    +−−−−−−−−−−−−−−−−−−−−+  |
| [[Prototype]]  |−−−>|      (object)      |  |
| text: 'a text' |    +−−−−−−−−−−−−−−−−−−−−+  |
+−−−−−−−−−−−−−−−−+    | [[Prototype]]      |−−+
| setData:[Ref55462] |−−−−>(function)
+−−−−−−−−−−−−−−−−−−−−+
Then after:
newObj.setData(data);
...you have something like:
+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+
|                                                |
\    +−−−−−−−−−−−−−−−−+                          |
data:[Ref54611]−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+−−>|   (object)     |                          |
+−−−−−−−−−−−−−−−−+                          |
| [[Prototype]]  |−−+                       |
| text: 'a text' |  |                       |
+−−−−−−−−−−−−−−−−+  |                       |
\                       |
+−−−−−−−−−−−−−−−−−−+                             +−>(Object.prototype)  |
newObj:[Ref74135]−−−>|   (object)       |                            /                       |
+−−−−−−−−−−−−−−−−−−+    +−−−−−−−−−−−−−−−−−−−−+  |                       |
| [[Prototype]]    |−−−>|      (object)      |  |                       |
| text: 'a text'   |    +−−−−−−−−−−−−−−−−−−−−+  |                       |
| data: [Ref54611] |−−+ | [[Prototype]]      |−−+                       |
+−−−−−−−−−−−−−−−−−−+  | | setData:[Ref55462] |−−−−>(function)           |
| +−−−−−−−−−−−−−−−−−−−−+                          |
|                                                 |
+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+
Note that the conceptual value "[Ref54611]" is in both data (the variable) and newObj.data (the property). You never actually see the value of an object reference in code, but you can think of them as numbers telling the engine where the object is.

Here is another answer: It's a classic reference vs. value question.
With JS, the case is the latter as objects are always referenced.
You can find examples here:
Javascript by reference vs. by value

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:02/03/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><javascript-objects>', 'Title': 'Javascript Object.create: what happens to memory when data is set?', 'ViewCount': 56, 'id': 54503218, 'user_AboutMe': "<p>For fun: Love playing guitar and some mandolin. Like folk music. The more basic, the better.</p>\n<p>For fun and for a living: I try to keep up with latest web i.e. Javascript/node.js, HTML, CSS etc technologies and developments. I am self trained, so self teaching new subjects has always been second nature. I am a total Javascript/node.js enthusiast. Lately with a sparkle of Rust.</p>\n<p>I prefer FreeBSD over Linux and Jails over Docker even though it adds some extra work.</p>\n<p>The recent years I have seen a lot of hopes and promises coming true, which I was looking forward to when I started working on the web. And it's getting even more interesting.</p>\n<p>Being able to do full stack development and to do set up my own servers has provided me with a good skill foundation to get projects done within a reasonable time frame.</p>\n", 'user_AccountId': 369279.0, 'user_DisplayName': 'LongHike', 'user_Reputation': 3552.0, 'user_Views': 409.0, 'user_id': 716568.0}}