let, var, const etc.
Variables are a place to store data.
Ways of declaring a variable:
- let
- var
- const
- (nothing)
var is the legacy way of declaring variables.
var is function scoped.
what is a scope
can redeclare a variable in var
let is block scoped.
Got added in ES6
cannot redeclare
const is block scoped
Got added in ES6
must be assigned
cannot redeclare
Const doesnt allow you to change the value of reference. const doesnβt say that itβll always have the constant value. which means, you cannot reassign rather, you can change the properties or elements of the const value.
Few Rules before naming your variable:
- cannot be reserved words
- can start with letters or $ or _
- names are case sensitive
Data Types,
Hoisting: Is a weird behaviour of moving all the variable declartions to the top.
When I say declaration, it only means declations, not initializations.