Hacker News new | past | comments | ask | show | jobs | submit login

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.



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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: