JavaScript let is a keyword used to declare a variable in a block scope. It is a new feature in ES6 (ECMAScript 6) that allows you to create a variable with a limited scope, which is especially useful when working with loops, switch statements, and other control structures.
// Declare a variable using 'let'
let x = 10;
// Print the value of x
console.log(x);
// Declare a variable using 'var'
var x = 10;
// Print the value of x
console.log(x);
// Declare a 'let' variable
let x = 10;
// Print the value of x
console.log(x);
// Reassign the value of x
x = 20;
// Print the new value of x
console.log(x);
// Declare a 'var' variable
var x = 10;
// Print the value of x
console.log(x);
// Reassign the value of x
x = 20;
// Print the new value of x
console.log(x);
// Declare a 'let' variable
let x = 10;
// Print the value of x
console.log(x);
// Try to access x outside of the block it was declared in
console.log(x);