You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
projects are going to need to be consistent in let/const usage, some options
only use var (no let/const)
use var unless a variable needs to be block scoped, then use let.
use let for everything
use const where possible, otherwise use let
use const for values (strings, numbers, booleans, null, undefined) that are constant and other immutable things (frozen objects), otherwise use let.
recommendations should probably be something along the lines of pick a strategy and treat it like gospel. The difference between 4 and 5 is that for objects it's the reference to the object that is constant, not the values in the object. Since most object references are more often then not never redefined that means that in version 4 const ends up being used almost exclusively.
If we only wanted one let/const option then 5 would be the best.
The other thing about let and const is that they always have the exact scope they appear to have, meaning that declaring variables at the top of scope has less of an benefit but continues to have the downside of increasing the change a forgetting to declare a variable, e.g.
function(){leta,b,c;//stuffwhile(true){letd;//lots of stuff, not with d.}// lots of stuffd=9;//whoops}
meaning an argument could be made that for let and const it is a better practice to declare them when they are first assigned a value or as close to that as possible, e.g.
function(){// stuffleta;//non local variable.while(true){//stuffletb=something;a=somethingElse}}
The text was updated successfully, but these errors were encountered:
projects are going to need to be consistent in let/const usage, some options
recommendations should probably be something along the lines of pick a strategy and treat it like gospel. The difference between 4 and 5 is that for objects it's the reference to the object that is constant, not the values in the object. Since most object references are more often then not never redefined that means that in version 4 const ends up being used almost exclusively.
If we only wanted one let/const option then 5 would be the best.
The other thing about let and const is that they always have the exact scope they appear to have, meaning that declaring variables at the top of scope has less of an benefit but continues to have the downside of increasing the change a forgetting to declare a variable, e.g.
meaning an argument could be made that for let and const it is a better practice to declare them when they are first assigned a value or as close to that as possible, e.g.
The text was updated successfully, but these errors were encountered: