DEV Community

Discussion on: Copy by Value vs Reference

Collapse
 
aminmansuri profile image
hidden_dude

The true way to know if you're passing by reference in a language is this:

func f(ref val) {
val = newVal;
}

x = something
f(x)

If x is now equal to newVal then your language supports passing by reference (ex: in Pascal this works with var, or in C++ & notation). If x is still equal to "something" then I'm afraid you don't have true pass by reference.

Collapse
 
parenttobias profile image
Toby Parent

And that's why I suggest a different verb, pass by share. We are sharing that reference in an assignment to another variable, rather than passing the value itself. However the reference is tied to the immutable value, and not to the variable.

Javascript is weird, but once you grok, it actually makes a lot of sense.

Collapse
 
guillep2k profile image
Guillermo Prandi

That's a different discussion. The article is about assignments, not function calling.