2 ms·
There is no difference between pass-by-reference and pass-by-value for immutable objects (unless there is a way to check object identity). So if you call the Ja
by kevincox 4y ago
There is no difference between pass-by-reference and pass-by-value for immutable objects (unless there is a way to check object identity). So if you call the JavaScript primitive types Number, String, undefined, boolean, reference then all of them are immutable so there is no difference. Of course most people don't think of JS as passing a "reference primitive by value", they think about "passing an object by reference". Since all of the primitives are immutable it is probably then easier to think of JS as a pass-by-reference language from the semantic point of view. In fact if you really want to simplify you can imagine that every variable is just a reference to a value since it is equivalent.