Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/prevent-object-mutation

Tell us what’s happening:
I getting an error in console
[TypeError: Cannot assign to read only property ‘PI’ of object ‘#’]

Your code so far


function freezeObj() {
'use strict';
const MATH_CONSTANTS = {
  PI: 3.14
};
// Only change code below this line

Object.freeze(MATH_CONSTANTS);

// Only change code above this line
try {
  MATH_CONSTANTS.PI = 99;
} catch(ex) {
  console.log(ex);
}
return MATH_CONSTANTS.PI;
}
const PI = freezeObj();
console.log(PI);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36.

Challenge: Prevent Object Mutation

Link to the challenge:

Yes. That’s the point of the lesson.

Once the object is frozen, you can no longer add, update, or delete properties from it. Any attempt at changing the object will be rejected without an error.

Got it
Thank you :slight_smile:

learner i am. what to do to keep on, pls

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.