Is there a way to know exactly when to use the let and const for your variables. I’m aware that const can not be altered after it is assigned, but sometimes when I am making a variable I find it hard to know when using either would be appropriate. Any advice.
Here’s my personal rule for it:
constby default when creating a new variable, this prevents variables that aren’t meant to be overriden from being unintentionally changed (and causing an error).
letif you are initialising a variable that you know you will have to update to a new value later on the code (as using
constwould prevent you from doing this).
That makes sense. Thanks for your answer.