ES6 - Prevent Object Mutation

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

function freezeObj() {
  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();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

ES6 - Prevent Object Mutation

What error are you getting?

it doesn’t accept it and pass me!

Please talk about what specifically the error message is and what you have tried to fix your code.

1 Like

To ensure your data doesn’t change, JavaScript provides a function Object.freeze to prevent data mutation.

Hint: Capital O

ReferenceError: object is not defined

it shows this error :
ReferenceError: object is not defined

Ok, so double check the syntax. Capitalization matters. Did you type Object or object?

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.