Can we change value of const object in JavaScript?
Answers (1)
Add AnswerA value of the const variable cannot be reassigned.
const val = 10; // 10 val = 15; // Uncaught TypeError: Assignment to constant variable
But you can change the properties of a constant object.
const car = {type:"Fiat", model:"500", color:"white"}; // Change a property: car.color = "red";
You cannot assign the whole object to a const variable
const car = {type:"Fiat", model:"500", color:"white"}; const car2 = {type:"Test", model:"200", color:"Red"}; car = car2; //Uncaught TypeError: Assignment to constant variable