DEV Community

Cover image for "Same Reference" vs. "Same Value"

"Same Reference" vs. "Same Value"

Basti Ortiz on November 05, 2018

In JavaScript and many other programming languages, variables are references to a value. By the Transitive Law of Logic and Mathematics, it then fo...
Collapse
 
drbearhands profile image
DrBearhands

By the Transitive Law of Logic and Mathematics, it then follows that references and values are one and the same

Unless I'm missing something here this is absolutely untrue and I'm not sure what it is you were trying to say. Referencing isn't transitive in the first place and even if it were, if you want equivalence you also need reflexivity and symmetry.

I think the memory graph is confusing, went should point to 'to', not to dev. Admittedly there's little difference with const values.

Other than that good writeup, many beginners struggle with this when exposed to mutability.

Collapse
 
somedood profile image
Basti Ortiz

Yes, I'm aware that went should point to 'to'. I only made it point dev for simplicity's sake, really. I hope it's still understandable nonetheless.

And regarding the Transitive Law, I was just trying to say that believing "references are values because variables are references to a value" should be avoided. Sorry if that didn't come out right.

Anyway, thanks for pointing (See what I did there?) this out.

Collapse
 
drbearhands profile image
DrBearhands

I would then argue in favor of rewording that sentence. The reason being that it might confuse people about what transitivity is (i.e. a property of a specific relation).

A reference to Frege's "Über Sinn und Bedeutung" might be a better fit.

Anyway, thanks for pointing (See what I did there?) this out.

nice one

Thread Thread
 
somedood profile image
Basti Ortiz

Oh, wow. This is some deep philosophical stuff.

Thread Thread
 
drbearhands profile image
DrBearhands

It is, though I must admit I personally detested the subject as I have very different views about what language is. But that's going way too far for a value/reference discussion :P

Thread Thread
 
somedood profile image
Basti Ortiz

Anyway, all jokes aside, I appreciate how you brought up the limitations and flaws of my article. Hopefully future readers will note your points. Thanks!

Collapse
 
kurtz1993 profile image
Luis Hernández

Congratulations! This is a very useful reference for people starting to learn JavaScript.

Collapse
 
somedood profile image
Basti Ortiz

Thank you so much! I really try my best to write informative articles.

Collapse
 
webdva profile image
webdva

This is a useful and excellent reference article you wrote.

Collapse
 
cdbartholomew profile image
Chris Bartholomew

As someone who is learning Javascript, this behavior seems like a truly frustrating bug waiting to happen. A referencing operator as a hint would have been nice. Thanks for explaining.

Collapse
 
somedood profile image
Basti Ortiz

Don't worry about it, my friend. You wouldn't really encounter anything frustrating from it. At least from my experience with JavaScript, I haven't had any problems with it. I think it stems from the fact that I try my best to be aware of my memory usage. Nonetheless, there is nothing to worry about. I promise that. Unless you are really trying to break your program/script, you won't break anything at all.