"Let " is the statement introduced by ES6(ECMA Script 6). What is this "Let" and how it behaves . Let us discuss about this in this post .
What is "let"
We are very familiar with key word "var" , which will help us to create a variable in Java script .
In ES6 this "let " word used to declare a variable . but both "let " and "var" behaves differently .
The main difference is scoping.
And one more thing to be noted is , variables declared with
What is "let"
We are very familiar with key word "var" , which will help us to create a variable in Java script .
In ES6 this "let " word used to declare a variable . but both "let " and "var" behaves differently .
The main difference is scoping.
var
will be scoped to the nearest function block and let
will be scoped to the nearest enclosing block (both "let " and "var" are global if outside any block), which can be smaller than a function block.And one more thing to be noted is , variables declared with
let
are not accessible before
they are declared in their enclosing block. As seen in the demo, this
will throw a ReferenceError exception.
Comments
Post a Comment