3 ms·
From a user perspective most languages make a mess out of these things and confuse people. In Javascript certain things are declared in a similar way, but some
by zzzcpan 9y ago
From a user perspective most languages make a mess out of these things and confuse people. In Javascript certain things are declared in a similar way, but some behave like values and some behave like references. Which makes it both pass-by-value and pass-by-reference.
- shkkmo 9y agoI believe that javascript always uses pass-reference-by-value, but simple types are immutable, which means that pass-reference-by-value is functionally identical to pass-by-value since there is no way to make changes to the immutable referent.
- pjmlp 9y agoWrong from CS point of view, references are also pass-by-value on JavaScript. If JavaScript allowed pass-by-referece, we would be able to do the following, function swap(x, y) { let c = x x = y y = c } let a = {a: 6, b: 7} let b = {c: 8, d: 8} swap(a, b) console.log(b) // Object {a: 6, b: 7} Meaning, pass-by-reference means being able to actually change the "pointer" used by the local variable.
- zzzcpan 9y agoI understand what you mean, but consider this to be an incorrect view on these things. They are not about CS, but about user experience.
- pjmlp 9y agoThe incorrect view is to teach wrong concepts just because some people rather learn based on gut feeling, than taking the effort to learn it properly.