It’s my understanding that you should use const by default for readability. The idea is if another dev is looking at your code and sees “let” they will know that variable will be reassigned later in the code. Makes the program easier to understand at a glance.
let has a block scope, i.e lives ans dies in the scope it is declared, whereas var is global or if in a function has a function scope and can be used anywhere.
this can lead to some nasty side effects and is as such not recommended.
47
u/MrMimmet Oct 26 '20
You should really avoid using 'var' to declare your variables.