In javascript, if I create a const array, I can still modify the object the variable points to:
// The const declaration creates a read-only reference to a value.
// It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
const x = [1,2,3];
x.push(4);
console.log(x);
x=55 // But this is illegal and will error
console.log(x);
Is there a way to make the elements in an array immutable as well? Similar to something like const int* const x; in C?
Object.freeze(x)will work