JavaScript · Junior · Question 51 of 75
Does this code throw an error?
const user = { name: "Ann" };
user.name = "Bob";- ✓Correct answer: No -
constforbids reassigning the variable, not changing the object it points to - 2Yes -
constobjects are frozen - 3Yes - but only in strict mode
Explanation
user = {} would throw a TypeError, but mutating properties is allowed. To make the object itself read-only, use Object.freeze (shallowly).