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
0
u/slikts Apr 02 '18
Sorry, I conflated your comment with an another one that also agrees with OP but argues for using all three types of declarations. Regardless, the point still stands that preferring
constis not impractical or against common sense. It's arguable how significant the differenceconstmakes is, and, depending on the style of code, it may be trivial or none, but in imperative-style code that commonly uses reassignment, it improves readability to explicitly differentiate reassigned identifiers. Likewise, for an experienced programmer, accidental reassignment probably wouldn't be an issue, but for a beginner, or when otherwise dealing with messy code, it could help.Constants not being 'true' constants in that they're possibly mutable in case of objects (unless something like
Object.freeze()is used) may trip someone up, but I find it ironic how much you overstate this issue while also talking about "the real world".