diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/es6/prevent-object-mutation/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/es6/prevent-object-mutation/index.md index 4b6b0c5ef7..82ab8752e4 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/es6/prevent-object-mutation/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/es6/prevent-object-mutation/index.md @@ -1,17 +1,15 @@ --- title: Prevent Object Mutation --- -![](//discourse-user-assets.s3.amazonaws.com/original/2X/3/3c8584a085a0deaea66b3400e6321eeadab552a2.jpg) - ![:triangular_flag_on_post:](https://forum.freecodecamp.com/images/emoji/emoji_one/triangular_flag_on_post.png?v=3 ":triangular_flag_on_post:") Remember to use **`Read-Search-Ask`** if you get stuck. Try to pair program ![:busts_in_silhouette:](https://forum.freecodecamp.com/images/emoji/emoji_one/busts_in_silhouette.png?v=3 ":busts_in_silhouette:") and write your own code ![:pencil:](https://forum.freecodecamp.com/images/emoji/emoji_one/pencil.png?v=3 ":pencil:") ### Problem Explanation: -We need to prevent `MATH_CONSTANTS` value from changing. +_You need to freeze the `MATH_CONSTANTS` object so that no one is able to alter the value of `PI`, add, or delete properties ._ ## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 1 -* Use Object.freeze(obj) to prevent object from being changed. +* _Use `Object.freeze()` to prevent mathematical constants from changing._ > _try to solve the problem now_ @@ -19,9 +17,9 @@ We need to prevent `MATH_CONSTANTS` value from changing. ![warning sign](//discourse-user-assets.s3.amazonaws.com/original/2X/2/2d6c412a50797771301e7ceabd554cef4edcd74d.gif) -**Solution ahead!** +**Solution Ahead!** -## ![:beginner:](https://forum.freecodecamp.com/images/emoji/emoji_one/beginner.png?v=3 ":beginner:") Basic Code Solution: +## ![:beginner:](https://forum.freecodecamp.com/images/emoji/emoji_one/beginner.png?v=3 ":beginner:") Basic code solution: ```javascript function freezeObj() { "use strict"; @@ -41,21 +39,10 @@ We need to prevent `MATH_CONSTANTS` value from changing. const PI = freezeObj(); ``` -![:rocket:](https://forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=3 ":rocket:") Run Code - # Code Explanation: By using Object.freeze() on `MATH_CONSTANTS` we can avoid manipulating it. -#### Relevant Links -* Object.freeze() - -## ![:clipboard:](https://forum.freecodecamp.com/images/emoji/emoji_one/clipboard.png?v=3 ":clipboard:") NOTES FOR CONTRIBUTIONS: - -* ![:warning:](https://forum.freecodecamp.com/images/emoji/emoji_one/warning.png?v=3 ":warning:") **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution. -* Add an explanation of your solution. -* Categorize the solution in one of the following categories — **Basic**, **Intermediate** and **Advanced**. ![:traffic_light:](https://forum.freecodecamp.com/images/emoji/emoji_one/traffic_light.png?v=3 ":traffic_light:") -* Please add your username only if you have added any **relevant main contents**. (![:warning:](https://forum.freecodecamp.com/images/emoji/emoji_one/warning.png?v=3 ":warning:") **_DO NOT_** _remove any existing usernames_) - -> See ![:point_right:](https://forum.freecodecamp.com/images/emoji/emoji_one/point_right.png?v=3 ":point_right:") **`Wiki Challenge Solution Template`** for reference. +### Resources +- ["Object.freeze()" - *MDN Javascript reference*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)