I'm working in a project with several javascript files and part of what I'm doing right now is both migrating existing code to use newer ES6+ features as well as making sure we're abiding by the AirBnB Eslint Rules.
So, given that context, this is the specific situation:
let meta = [a.platform];
And right below that:
meta.push(a.browserName ? a.browserName : 'any');
So now the linter is giving me a warning: 'meta is never reassigned. Use const instead'.
I understand that meta = somethingNew
would be reassigning the variable. But in this case, isn't this variable also something different than what it used to be when it was created?
or, to make it even more clear
Can I use a const to define an array that will receive new items? If not, why?
Also, if not: why is the linter throwing a warning?
Object
types (likeArray
s) just means to rebind a name with another reference (to anotherObject
type). When you mutate anObject
type as in your example, you merely change its properties, but not the underlying reference. – Afterdeck