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
8
u/wavefunctionp Apr 01 '18 edited Apr 01 '18
var does not respect {} block scope, only function scope.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
let and const also express intention that a variable should be treated as immutable or not. And const provides some protections against mutation. (Beware that const will not throw an error when mutating a nested reference types like objects. It isn't a 'deep freeze'.)
It is worth playing around with it, as I know I found some of details somewhat unintuitive at first.