@averma7,
averma7 wrote:
Declaring an object as const makes it impossible to change that object. true or false?
First of all. This is a computer programming question. Philosophy is meaningless (at least in this context
).
The answer is "No". This is a poorly worded question, but I am pretty sure that they are asking this to see if you understand that const does not make an object immutable.
Consider the following code (and you can easily try this in JSFiddle):
Code:
var foo = { one : "red", two : "blue", three : "green"};
const bar = foo;
foo.one = "yellow"; // legal (no error). You are changing the object
bar = {animal: "dog"}; // will cause error. You are making an assignment.
The const keyword will prevent you from assigning to the variable. It will not prevent you from changing the object that has already been assigned.
Quote: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. For instance, in the case where the content is an object, this means the object's contents (e.g., its parameters) can be altered.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const