I am a big fan of latest programming conventions and latest additions to programming languages. Recently I read in Google Guidelines that we should use const
and let
instead of var
.
Now in my project I have namespace object variables (if that's what they are called, correct me please if I am wrong) like this
var myObj = {
func1: {},
func2: {}
};
var myOtherObj = {
var1: 'foo',
var2: 'bar'
};
How should I name these objects now using the new conventions, with const
or with let
? I am confused because I don't know if these big objects change over time, or not...
const
doesn't prevent objects from changing (said otherwise it doesn't freeze them). It prevents the value of variables to change.
For example you can still do
const myObj = {
func1: {},
func2: {}
};
and then
myObj.fun3 = function(){...
What you can't do with a variable declared with const
(but which doesn't seem to be your will) is
myObj = {};
Modules are usually declared with const
.