Tell us what’s happening:
This is the code I just practiced, so if I’m not mistaken, Object.freeze can freeze the function?
Your code so far
function freezeObj() {
"use strict";
const MATH_CONSTANTS = {
PI: 3.14
};
// change code below this line
Object.freeze(freezeObj)
// change code above this line
try {
MATH_CONSTANTS.PI = 3.14;
} 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; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/77.0.126 Chrome/71.0.3578.126 Safari/537.36.
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.
Hi, you tried freeze one function inside itself, search the real object you need freeze.
Both arrays and functions are objects, so yes you can use Object.freeze() with them. Although I’m not really sure I see a point of using it on a function.