workabout

What is the purpose of the let keyword?

The let the statement declares a block scope local variable. Hence the variables defined with the let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the var keyword used to define a variable globally, or locally to an entire function regardless of block scope. Let's take an example to demonstrate the usage,

let counter = 30;

if (counter === 30) {

let counter = 31;

console.log(counter); // 31

}

console.log(counter); // 30 (because if block variable won't exist here)