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.
He/him, developer, builder of things both tangible and abstract, practitioner of yoga and ukulele... All-around complicated monkey.
https://www.buymeacoffee.com/tobyplaystheuke
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.
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.
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.
That's a different discussion. The article is about assignments, not function calling.