Hacker News new | ask | show | jobs
by epidemian 4010 days 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.
2 comments

The 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.

'const' is misleading, it doesn't set your variables as immutable. Fine for expression, but not for actual practicality.
It 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.