I don't think pass-by-reference exists in JavaScript. That's a term popularized by C++ or C. In those languages, objects can either be values or reference, therefore you need the pass-by-semantics to differentiate between the two.
JavaScript is more similar to Java in that both languages have no concept of value types. All objects are references, which means all values are references too, therefore there is no need to make a distinction about call semantics. (Actually now Java has Record types which are kinda like value types, except that they are only shallowly immutable). Therefore, every time you pass an object to a function, if that object is mutable, any changes made to it will reflect outside the function.
i.e. if the Boolean type had a mutable field, you will see that mutation after passing that boolean to a function which changes it. The same will not be true in languages with true value types like C++ or C. A value type in C++, even with mutable fields will not reflect in the original object outside the function, if the function were to mutate it.
Hey π Not sure if I'm following if this comment describing the same issue as this one or is it another issue? Can you take a look at the previous one?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I don't think pass-by-reference exists in JavaScript. That's a term popularized by C++ or C. In those languages, objects can either be values or reference, therefore you need the pass-by-semantics to differentiate between the two.
JavaScript is more similar to Java in that both languages have no concept of
value
types. All objects are references, which means all values are references too, therefore there is no need to make a distinction about call semantics. (Actually now Java has Record types which are kinda like value types, except that they are only shallowly immutable). Therefore, every time you pass an object to a function, if that object is mutable, any changes made to it will reflect outside the function.i.e. if the
Boolean
type had a mutable field, you will see that mutation after passing that boolean to a function which changes it. The same will not be true in languages with true value types like C++ or C. A value type in C++, even with mutable fields will not reflect in the original object outside the function, if the function were to mutate it.Hey π Not sure if I'm following if this comment describing the same issue as this one or is it another issue? Can you take a look at the previous one?