Tell us what’s happening:
A very confusing behavior in the challenge. After following the instruction on what to do, the console displayed the following error message:
TypeError: Cannot assign to read only property 'PI' of object '#<Object>'
I wasted quite sometime trying to figure out why, until I found in another forum post that the the code will pass as it is, in spite of the console error message.
I would really appreciate it if anyone can help and explain why this is so. Is this a challenge test error that need to be corrected? Or is it something else.
.
Your code so far
function freezeObj() {
"use strict";
const MATH_CONSTANTS = {
PI: 3.14
};
// change code below this line
Object.freeze(MATH_CONSTANTS)
// 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_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/prevent-object-mutation