ES6: Prevent Object Mutation

As seen in the previous challenge, const declaration alone doesn’t really protect your data from mutation. To ensure your data doesn’t change, JavaScript provides a function Object.freeze to prevent data mutation.

  • Why is the word Object capitalized, I was under the impression proper syntax was lowercase for first words, then .freeze is lower case. Is camelCase not supposed to be used for functions.

I can go with it just curious it adds a layer of confusion.

Object is a class, and freeze is a static function of that class

That’s slightly misleading in a sense if you come from other programming languages, as JS classes can be quite different in many ways.

The standard practise is make functions that are designed to be classes (earlier standards) and working with the new keyword have an uppercase name, which carries on with the newer ES6 style of classes too

You can read more about Object specficially here:

Or (ES2015) classes here:

1 Like