const alone does not guarantee protection for your data or let me say it does not protect your data from mutation,
Example:
const GREETING = {
name : "Joel",
info : "Goodday!"
}
Though the above code makes use of const i can still update the values via the code below
GREETING.name = "Elijah";
But this could easily be avoided by making use of Object.freeze() to freeze our const variables.
Just add this line of code and you will discover that the values cannot be updated.
Object.freeze(GREETING);
GREETING.name = "Elijah"; // This will now be ignored due to mutation
const alone does not guarantee protection for your data or let me say it does not protect your data from mutation,
Example:
Though the above code makes use of const i can still update the values via the code below
But this could easily be avoided by making use of
Object.freeze()
to freeze our const variables.Just add this line of code and you will discover that the values cannot be updated.
For more clarification check: freecodecamp.org/learn/javascript-...