I'm wondering what is the difference between let and const in ECMAScript 6. Both of them are block scoped
1 Answer
The difference between let and const is that once you bind a value/object to a variable using const, you can't reassign to that variable. Example:
const something = {}; something = 10; // Error. let somethingElse = {}; somethingElse = 1000; // This is fine. Note that const doesn't make something immutable.
const myArr = []; myArr.push(10); // Works fine. Probably the best way to make an object (shallowly) immutable at the moment is to use Object.freeze() on it.