The canonical example is a function that swaps the variables passed to a function:
a, b = 10, 20
swap_fn(&a, &b)
a == 20 # true
Since the above are primitive data types (ints), in order to make this work, the language needs to generically support passing the address (reference) of the variables. Java¹/Python² etc. are not able to do this; they copy the value of the variable and send it to the function, which will operate on the copy.¹=at least, last time I've checked, which was long ago :)
²=funny to think that at least in Python, one can mess with the global register of the variables, and actually accomplish that
Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(d):
... d['foo'] = 'bar'
...
>>> a = {}
>>> f(a)
>>> a
{'foo': 'bar'} Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>> def f(d):
... d = {'foo': 'bar'}
...
>>> a = {}
>>> f(a)
>>> a
{}
does not modify the passed in dictionary, because the reference 'd' itself is passed by value. So the function doesn't change what d references for the caller. Java works the same way.I guess my understanding could be technically wrong in some way, but it seems to reflect what happens.
I've been developing for 25+ years in any language you can imagine, and know how to use pass by ref just fine, and know there are situations where it might be the best solution.
But I can't remember the last time I've used pass by ref. It's really just a coding style quirk for me, I find it "ugly" and it breaks my train of thought when reasoning through the flow of code. I certainly don't begrudge anyone who uses it though.
And OP's anecdote about the interview is certainly disheartening. You'd hope the interviewer would at least be open to the idea of learning something new. I've learned countless things from developers I've interviewed over the years, and I was incredibly happy about it each time.
Edit: In re-reading your comment and below replies it seems you may be misunderstanding what's being discussed. Yes, the things we pass into and out of functions tend to be object references by default. But when we say "pass by ref" (in some languages at least) we mean, essentially, modifying a value in a calling function without actually returning anything from the called function. That's a horrible way to explain it, but the MS documents for the "ref" keyword do a good job of showing examples:
https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
Like...duh?
I suppose that's why I find Golang less weird to work with than others in my cohort. I spent a semester in the depths of C and OpenGL so I'm intimately familiar with by-value vs by-ref.
One necessary (but insufficient) test you can use to determine if your language has call by reference or call by value is whether you can implement a swap function. In the languages you list, a swap function is not possible to implement, whereas in C++ it is, which tells you that those languages do not implement pass by reference.
For example the Java Language Specification states in section 8.4.1 that Java is pass by value:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html...
ECMAScript's Language Specification also states in section 10.6 that it uses pass by value semantics, although it's much more formal about the specific approach it uses:
https://262.ecma-international.org/5.1/
I can't link to the specific section but you can review the semantics of MakeArgGetter and MakeArgSetter which are specified to produce arguments bound to the *value* associated with the name, as opposed to a reference.
Python does not have a spec that I can reference, but given that its argument semantics follows those of Java, and once again the inability to write a swap function, it should not be too difficult to deduce that Python also passes by value.