The 'let' keyword was introduced in ES6 to help clarify intent.
The 'var' keyword should keep a variable visible within it's block, only.
But in fact, it was attached to the function it is declared in, via hoisting.
Which means it could be accessed outside of it's block.
The 'let' keyword was then introduced to make clear that a variable declared within a block, is only visible within this block.
As opposed to 'var' who could be visible outside of that block.
The 'var' keyword should keep a variable visible within it's block, only.
But in fact, it was attached to the function it is declared in, via hoisting.
Which means it could be accessed outside of it's block.
The 'let' keyword was then introduced to make clear that a variable declared within a block, is only visible within this block.
As opposed to 'var' who could be visible outside of that block.
Comments
Post a Comment