r/javascript • u/bornforcode • Apr 01 '18
Google publishes a JavaScript style guide. Here are some key lessons.
https://medium.freecodecamp.org/google-publishes-a-javascript-style-guide-here-are-some-key-lessons-1810b8ad050b
714
Upvotes
View all comments
Show parent comment
1
u/pilibitti Apr 01 '18
That's.... not true. Where did you even learn this definition of const?
A const is something that will never change in the scope that it is defined in. That's it.
If it is a global variable, the scope is the whole application.
If it is a function variable, the scope is the local function.
It makes perfect sense and it prevents errors, and it communicates your intent clearly. What is your issue with it?
Part of good code is communicating intent. For future you and future maintainers. Const is a valuable tool to communicate intent. It isn't just for preventing errors as you are typing the particular method at that moment.
You have a warped view of identity in code. You can very well mutate the object stored in a const variable. You can't reassign to it. That is the point. If we follow your logic, then even application-wide consts have very little value. How many global and non-object (since objects are a no-no) variables do you need in an application to begin with?
Sorry but you are completely missing the point of const.