The let keyword in ES6

We will use the let keyword in ES6 to declare a block scope variable, for example if we only want a variable to be used in a block but not outside the block then we can simply use the let keyword to declare that variable in that block.

function letDemo(){
	if(true) {
		let a = 5;


ReferenceError: a is not defined will appear in the developer console if you run the code above because the ES6 script fails to access the a variable outside the block scope.

Like this post? Kindly share!