ES6: Prevent Object Mutation small sugestion


I’m wondering if it wouldn’t be a good idea to add information that Object.freeze() works only at a shallow level? So if there is an object nested inside other object we should use Object.freeze() on both objects to make sure that no data will be mutated.

For example:

const obj = {
  prop1: 1,
  prop2: 2,
  prop3: [3,4,5]

Object.freeze(obj); // prevents obj from mutations

obj.prop3[0] = 9; // still can be mutated
obj.prop3 // [9,4,5]
1 Like

@Bartek You can create a GitHub issue with your suggestion and we can discuss this further. It could be added as a note below the description section as long as it can be written concisely. The Free Code Camp curriculum is not meant to be a comprehensive JavaScript, so we can not add everything. That being said, go ahead and create the issue and we will see what others think.

Thank you.