Var, Let & Const
Var
Variable defined with var is function-scoped.
Any variable defined with var is hoisted, but only its declaration, not its value.
|
Let
Variable defined with let are block-scoped. Unlike var, let does not hoist its variable declaration.
When we use variables with Var and Let, we can change their value.
Since variables defined with let and const cannot be hoisted, arrow functions (which are initiated with let or const) also can not hoist, unlike functions declaration.
|
Const
As the name suggests, the variable initiated with const remains constant. Means the variable are immutable.
Interesting Fact
When using javascript in sloppy mode (non-strict mode), we can declare variables without var, let, or const. The variable cannot be initiated without any value. The scope of these variables becomes global irrespective of where they are initiated.