|
|
|
|
|
by zarathustreal
2150 days ago
|
|
Yes precisely this. The person above you might be unaware of the fact but JavaScript (and all other languages that I’m aware of) does indeed make use of pointers albeit indirectly. When you use const and initialize it as a JS object the value in the variable is a “pointer” (call it what you will, it points to or references a memory location) and is indeed immutable. You cannot change the value of the variable. You can, however, change the value of a different variable (such as a property of the object it references) but at that point you’re not longer talking about the same variable. So in a sense “no, it’s not immutable” but in another sense, yes it actually is. It makes the most sense to talk about the value that the variable holds rather than the object it references when speaking of immutability because there also exist primitive values in JS that are immutable in exactly the same way, except they are not references (or pointers) they are just values. So instead of needing to keep the additional “gotcha, object references are immutable but the properties of that object are not frozen” you can simply understand the literal semantics. Of course that is just my personal opinion |
|
Do you think your 200-word explanation is easier for a beginner to understand than "this value is immutable — it will never change"?
My initial argument was that JavaScript is a terrible choice for learning FP, precisely because it has so many caveats and is notoriously poorly understood, even by people who use it every day. Your lengthy explanation proves my point.