I’ve completed and passed the ES6: Prevent Object Mutation
lesson using the Object.freeze()
method.
Here’s the code:
'use strict';
const MATH_CONSTANTS = {
PI: 3.14
};
Object.freeze(MATH_CONSTANTS);//Line 6
try {
MATH_CONSTANTS.PI = 99;
} catch(ex) {
console.log(ex);
}
return MATH_CONSTANTS.PI;
}
const PI = freezeObj();
console.log(PI)//Logs 3.14 as expected
The code passed but I’m getting the following error:
[TypeError: Cannot assign to read only property 'PI' of object '#<Object>']
Did I do something wrong?