3 ms·
The main benefit of let/const over var is that it's block scoped. The benefit of const over let is pretty much nothing, much. It only prevents some limited form
by megous 7y ago
The main benefit of let/const over var is that it's block scoped. The benefit of const over let is pretty much nothing, much. It only prevents some limited form of re-binding. You can still easily re-bind const variables from inside a function:
const x = 1;
(function() {
const x = 2;
console.log(x);
})()
or from an argument:
const x = 1;
(function(x) {
console.log(x);
})(2)
So it has limited value in any code that uses closures.