JavaScript Quiz Question #3: Deep Object Mutability
Nick Scialli (he/him)
Posted on April 23, 2020
Consider the following object representing a user, Joe, and his dog, Buttercup. We use Object.freeze
to preserve our object and then attempt to mutate Buttercup's name. What gets logged?
const user = {
name: 'Joe',
age: 25,
pet: {
type: 'dog',
name: 'Buttercup'
}
};
Object.freeze(user);
user.pet.name = 'Daffodil';
console.log(user.pet.name);
A) Daffodil
B) Buttercup
C) An error is thrown
Put your answer in the comments!
💖 💪 🙅 🚩
Nick Scialli (he/him)
Posted on April 23, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.