Let vs Var vs Const
Let statement is block-scoped and not a Global scope local variable used for initializing a statement. This statement can be used in function as it is function-scoped and one of the main character of let statement is that it can be reassigned.
Var statement is also used for variable declaration and it is Global scoped variable. Variable declared with var is defined throughout the program.Var is defined throughout the function but not if its declared in a block as it is not block-scoped.
Var statement can be reassigned.
When we declare a variable with let, we can reassign its value later on. Thats great but what if we dont want to reassign its value, for those, we have const. Const is function-scoped and block-scoped and it is not defined throughout the program as it is not global-scoped. If you try to reassign const variable it will throw a type error.
const variables in objects and arrays.
You cannot overwrite an object but yes you can change its properties.
reassigning a value of keys is possible as mentioned
In arrays, you cannot assign an array to a const variable.
But you can push items to the array.
Variables declared with var can be accessed even before they are declared. The reason for this behaviour is that they are hoisted up to the top of the scope. When you declare some variable without any statement it gets declared as
Var variable is something I will not recommend to use as it is not used in the Industry. Let and Const are the one which you will be using. choosing them is easy as if you want to reassign its value use let and if you are then got for const variable.
Getting strong with the fundamentals is the only path to Glory.
Wish you very all the Best, Keep Practicing, Peace..
I m a self learnt NodeJS Developer from India.