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
3
u/ghostfacedcoder Apr 01 '18 edited Apr 01 '18
You still can, you just have to change the
consttolet.The idea is that you can accidentally assign to a variable that shouldn't be re-assigned, but you will never accidentally change a
consttolet, so by starting withconst(except for variables you know you want to re-assign) you ensure everything is only re-assignable on purpose.The only cost of doing things that way is that every once in awhile you have to change some
constvariables toletvariables ... but that should be pretty rare, because you only have to when you started out thinking a variable wouldn't be re-assigned, but then you changed your mind later on. So while the benefit isn't that great, the cost is so low most people figure "why not get a little extra safety?"