I am beginner with javascript and I try to stick to good programing practices, like the use of constants for values that don't change.
For example, I would like to store the settings in a constant:
const settings = {};
settings.backgroundColor = '#FFF';
settings.textColor = '#333';
settings.shadowColor = '#DDD';
I noticed that even though "settings" is a constant, I can re-assign other values later during the execution of the program for example I can reassign values here without triggering errors:
settings.backgroundColor= '#FFF';
if ( test === 1) {
// my block of code
}
settings.backgroundColor= '#F00';
settings.backgroundColor= '#00F';
settings.backgroundColor= '#123';
This code is valid and the console does not throw any kind of error.
Is there a solution to have real constants stored inside my object "const settings"?
I tried this but it did not work:
const settings = {};
const settings.backgroundColor = '#123';
const settings.textColor = '#333';
const settings.shadowColor = '#DDD';
It throws an error "Uncaught SyntaxError: Identifier 'settings' has already been declared"
This question is not very important since my code works properly, I just try to have good practice of development.
Thank you for the help !