3 ms·
In JS `const` just means that you can't reassign that variable, not that the value it references can't change: const a = {foo: 5}; a.foo = 42; // This is p
by epidemian 11y ago
In JS `const` just means that you can't reassign that variable, not that the value it references can't change:
const a = {foo: 5};
a.foo = 42; // This is perfectly valid.
a = 'nope'; // But this isn't. It raises a SyntaxError.
- orthoganol 11y agoThe purpose of the code wasn't to illustrate how to use const. It was to show how they want you to always use const with complex types.
- anselmoars 11y ago'const' is misleading, it doesn't set your variables as immutable. Fine for expression, but not for actual practicality.
- icebraining 11y agoIt does set your variables as immutable, just not your values. It makes sense if you see variables in these languages for what they are: references to values.