Try and catch statement

Tell us what’s happening:
Describe your issue in detail here.
In this code, what’s the significance of try and catch statement?

  **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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15

Challenge: Prevent Object Mutation

Link to the challenge:

Try-catch basically says “try to do this, and use this fallback behavior if it fails”.

1 Like