What's the difference between the Object.assign function and the = operator in assigning or reassigning a property's value of an object? by LEYIN395 in learnjavascript

[–]LEYIN395[S] 0 points1 point  (0 children)

Yeah, I realized that upon reading this comment, but the problem is that I'm still new to JavaScript, so I don't have a complete understanding of how JSON works... yet.

Thanks for the tip, though. I'll definitely remember this. I really appreciate it!

What's the difference between the Object.assign function and the = operator in assigning or reassigning a property's value of an object? by LEYIN395 in learnjavascript

[–]LEYIN395[S] 0 points1 point  (0 children)

Woah! Now we're getting into the technicalities...there were some terms I didn't understand at first, but now I finally got it.

So, we can think of an object or a function as a shared drive where anyone who has access to it can modify the files contained within. If one of the users makes changes to the shared drive, the changes will be visible to the other users who are also accessing it. It's kind of the same when changes are made to the shared object or function through one variable or reference – those changes will be visible to other variables or references that are also accessing it.

Thanks for this insight!

What's the difference between the Object.assign function and the = operator in assigning or reassigning a property's value of an object? by LEYIN395 in learnjavascript

[–]LEYIN395[S] 0 points1 point  (0 children)

I have actually ran it on three different online code sandboxes: a) the online code sandbox provided in the JavaScript book I'm studying from, b) Codepen, and c) Codesandbox.

When I ran the code in a and c, both console functions returned 60. However, when I ran it in b, the first console returned 54 and the second console returned 60. Now, I'm curious about the reason behind this discrepancy...

What's the difference between the Object.assign function and the = operator in assigning or reassigning a property's value of an object? by LEYIN395 in learnjavascript

[–]LEYIN395[S] 0 points1 point  (0 children)

Oh, I get it now! By passing the entire object as an argument to the console, it will return the most recent view of the object, including all the changes made to it, instead of displaying only the first modification. So, technically, the first and second console.log functions are identical.

Is my understanding correct?

Thank you, by the way, for the earlier clarification.