JavaScript Let

The let keyword is used for variables declaration in JavaScript with block scope. The variables defined with JavaScript let word cannot be redeclared. We accidentally cannot do this.

JavaScript Let

The syntax for the let keyword is given below:

JavaScript Let – Global Scope

The variables that we declared in the main body or outside the function have global scope means we can access them anywhere in the code.

JavaScript Let – Block Scope

JavaScript has only Function Scope and Global scope before ES6 (2015). The let and const were the new keywords that were introduced. These are used to provide the facility of Block Scope means the variables we declared inside the { } block cannot be accessed outside the block.


The variables we defined with the let keyword can be hoisted to the top of the block but we cannot initialize these variables. It means that using the let variable before its declaration will cause a ReferenceError: