Back to the lesson

Constant objects?

importance: 5

Is it possible to change an object declared with const, how do you think?

const user = {
  name: "John"
};

// does it work?
user.name = "Pete";

Sure, it works, no problem.

The const only protects the variable itself from changing.

In other words, user stores a reference to the object. And it can’t be changed. But the content of the object can.

const user = {
  name: "John"
};

// works
user.name = "Pete";

// error
user = 123;