Max Heiber
1 min readSep 5, 2017

--

JS is always pass by value, where values can themselves be references (pointers).

Primitives such as strings are immutable, but there is a difference between whether a value is mutable and whether a variable that points to a value can be reassigned.

Parameters in JS are always reassignable, regardless of whether they originally pointed to a primitive or compound value.

C++ and Swift, on the other hand, truly have pass-by-reference. The feature is called “in-out parameters” in Swift, and The Swift Programming Language defines it like this:

1. When the function is called, the value of the argument is copied.

2. In the body of the function, the copy is modified.

3. When the function returns, the copy’s value is assigned to the original argument.

You’ll see no mention of “pass by reference” in the ES2018 spec.

--

--

No responses yet