Newbie question:
Can const objects be deleted or overwritten in js?
const a = function myFunc(){}; // some code to delete 'a' and 'myFunc()' here.
Newbie question:
Can const objects be deleted or overwritten in js?
const a = function myFunc(){}; // some code to delete 'a' and 'myFunc()' here.
A downside to using const is that you cannot clear the variable at will (const prevents it from being changed in any way).
If the variable is not in the global scope, then the garbage collector will take care of it when it goes out of scope. If it is in the global scope, then you cannot get rid of it. The work-around is to stop using const for variables that you wish to modify.
Properties of an object, assigned to a const variable are not affected by the const declaration as the const delcaration affects the variable, not the the contents that it points to. You can use Object.freeze() or Object.seal() if you want to affect properties of an object.