Re:Using const/let instead of var can make JavaScript code r...
by jpcooper on Wednesday October 21, 2020 @04:52AM
(#24845973)
There are two possibilities in C++. I am not sure what the situation is in Java.
It is possible to define a pointer to an object whose contents may not be changed. This is done with ‘const * type object’.
If you want a pointer whose value must not change, but do not care about the contents of the pointed to object, you would write ‘type * const object’.
Re:Using const/let instead of var can make JavaScript code r...
by eMSF on Wednesday October 21, 2020 @05:52AM
(#24846224)
You ought to have mentioned that pointers of the latter type are quite rare in C. A mention of const pointer practically always means a pointer-to-const: a pointer you can't write through. Often you can still "re-bind" such pointer to another object – in both ways the polar opposite of JS const.
Of course, in C++ there are const references as well, and in this case const also means you can't modify the referenced object (in any case in C++ you can never re-bind a reference).
Re:Using const/let instead of var can make JavaScript code r...
by jansan on Wednesday October 21, 2020 @06:16AM
(#24846347)
It's the same in Java and never caused any problems. You just have to understand what const does. What the OP is looking for is Object.seal() and Object.freeze().
This is a pointless discussion.
const fixed the pointer but don't prevent user change the value in the storage it point to.