let and const in ES6
ECMAScript 2015 or commonly called as ES6 specification of JavaScript introduced let and const
letlet is the new var.
let could be used to declare variables, just like var.
Differences between let and var are
letvariables are block scoped.- Global
letvariables are not properties on the global object. - Loops of the form
for (let x...)create a fresh binding for x in each iteration. - It’s an to try to use a
letvariable before its declaration is reached. - Redeclaring a variable with
letis a SyntaxError.
constVariables declared with const are like let except you can’t assign
to them, except at the point where they are declared.
The const declaration creates a read-only reference to a value.
It does not mean the value it holds is immutable, just that the
variable identifier cannot be reassigned.
References
Categories :
JavaScript
ES6