JavaScript · Junior · Question 51 of 75

Does this code throw an error?

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

Explanation

user = {} would throw a TypeError, but mutating properties is allowed. To make the object itself read-only, use Object.freeze (shallowly).

Further reading

Problem with a question

JavaScript · Junior · question 51

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