Javascript novice here. From https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/ :
- They are all hoisted to the top of their scope. But while var variables are initialized with undefined, let and const variables are not initialized.
- While var and let can be declared without being initialized, const must be initialized during declaration.
So "const" is clear that it's initialized as the value it was originally declared as.
"var":
a) not declared, initialized as undefined
b) declared, initialized accordingly
"let":
a) not declared, initialized as ______???______
b) declared, initialized accordingly
What is "let" initialized as if it's not declared at first?
var. Refactor it out of exisitng code if possible. 2) Always useconstif the value won't change. For example, if you create an array to push elements into it later, the array still can beconstbecause its a reference that won't change. 3) Useletonly if you are sure the variable will change. For example, for loop indexes. 4) Putconstandletdeclarations as close to where they are used as possible, just like in other programming languages, and forget about their hoisting.