What is the difference between using the keywords let and const for block-scoped declarations in ES6?
let is used for constant values while const is used for variables that can change
let can only be used to declare variables inside functions while const can be used anywhere
there is no difference between let and const
let can be reassigned while const cannot
The let and const keywords are used for block-scoped variables in ES6. While both let and const are block-scoped, the key difference is that let can be reassigned with a new value while const cannot. In other words, const creates a constant variable that cannot be changed once it has been assigned a value, while let creates a mutable variable that can be reassigned multiple times within the same scope.
// let variable
let myVariable = 1;
myVariable = 2; // This is allowed
// const variable
const myConstant = 1;
// myConstant = 2; // This is not allowed
console.log(myVariable); // Outputs 2
console.log(myConstant); // Outputs 1