JavaScript · Junior · Question 5 of 75

What happens?

const user = { name: "Ann" };
user.name = "Bob";

Explanation

const fixes the reference: user = {} throws, but the object's contents can change. To prevent property changes, use Object.freeze (shallowly).

Further reading

Problem with a question

JavaScript · Junior · question 5

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz