It's pass-by-value in both cases, like Java. The difference is that both items in your tests are objects, whereas in Java one would have been a primitive, the other an object. But whether something is a primitive or an object has no bearing on pass-by-value vs. pass-by-reference. Pass-by-value vs. pass-by-reference has to do with what the called method can do to the variables in the calling context that are passed into it.
Let's ignore both languages and objects and just look at what pass-by-value vs. pass-by-reference actually mean. I'll use pseudo-code in a vaguely B/Java/C/C++/C#/D syntax:
Function Foo(arg) {
arg = 6
}
declare variable a
a = 5
Foo(a)
output a
If a
is passed by value, the output is 5. If a
is passed by reference (a reference to the variable a
is given to Foo
), the output is 6, because Foo
is working on a
via a reference to the variable.
Note that there's a substantial difference between your two tests.
In your first test, you're assigning an entirely new value to a
:
a = a + 5
You're not modifying the version of a
passed into the method, you're using that value to assign a new value to a
.
In your second test, you're just modifying array
:
array.pop
Not, for instance:
array = ...put something entirely new in `array`...
In your test, since you're just modifying the thing that the object reference points to, not changing the reference, of course you see that modification. But if you'd actually assigned a new array to array
, that change wouldn't be apparent in the calling context.