Block scope in Javascript

Block scope in Javascript

In this article we are goanna to see about Block scope in Javascript and where we use these. which is most important when you are going to start your career in JavaScript. Please read and enjoy this article if you want to give any feedback about your experience, we welcome.




ES2015 introduced two important new JavaScript keywords: let and const.

These two keywords provide Block Scope variables in JavaScript

Variables declared with the var keyword cannot have Block Scope.

Variables declared with the let & const keyword can have Block Scope.

Variables declared inside a block {} cannot be accessed from outside the block

Ex: var
{
    var x =10;
}
document.write(x);

Ex:
let
{
    let x =10;
}
document.write(x);

Share:

0 comments

Please leave your comments...... Thanks