*In Javascript, there are 3 keywords you can use to declare a varible:
varletconstStarting with ES6, the let and const keywords are used, making the var keyword almost obsolete in usage. Using let and const is preferred.
When a variable is assigned a value with one of the above keywords, the variable is said to be initialized with the assigned value
let
- Variables assigned a value using the
letkeyword can be re-assigned to a different value- You can declare a variable with
letwithout assigning a value to the variable name
> In this case, the variable is automatically initialized with a default value ofundefined.
The var keyword functions similarly to let
const
- Variables declared with
constkeyword cannot be re-assigned
>conststands for "constant"
> trying to re-assign a value to aconstdeclared variable yieldsTypeError- A
constvariable must be initialized with a value
> declaring aconstvariable without a value yieldsSyntaxError